如果您想要完整代码,请发送消息

测试

image

image

结果

  1. 混淆矩阵

confusion_matrix 2. 精确度置信度曲线

P_curve

  1. 其他

results

训练 train_batch1

验证 val_batch1_labels

flutter_pytorch

  • flutter 插件,用于帮助运行 pytorch lite 模型进行分类,例如 yolov5 不支持 yolov7
  • iOS 支持(可以通过此链接 https://github.com/pytorch/ios-demo-app 添加)欢迎 PR

入门

用法

准备模型

  • 目标检测 (yolov5)
!python export.py --weights "the weights of your model" --include torchscript --img 640 --optimize

示例

!python export.py --weights yolov5s.pt --include torchscript --img 640 --optimize

安装

要使用此插件,请将 pytorch_lite 添加到您的 pubspec.yaml 文件中作为依赖项。创建 assets 文件夹并放入您的 pytorch 模型和标签(如果需要)。相应地修改 pubspec.yaml

assets:
 - assets/models/model_objectDetection.torchscript
 - assets/labels_objectDetection.txt

运行 flutter pub get

发布版

  • 转到 android/app/build.gradle
  • 在 release 配置中添加以下行

shrinkResources false
minifyEnabled false

示例

    buildTypes {
        release {
            shrinkResources false
            minifyEnabled false
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }

导入库

import 'package:flutter_pytorch/flutter_pytorch.dart';

加载模型

分类模型

ObjectDetection model:
```dart
ModelObjectDetection objectModel = await FlutterPytorch.loadObjectDetectionModel(
          "assets/models/yolov5s.torchscript", 80, 640, 640,
          labelPath: "assets/labels/labels_objectDetection_Coco.txt");

获取图像的目标检测预测

 List<ResultObjectDetection?> objDetect = await _objectModel.getImagePrediction(await File(image.path).readAsBytes(),
        minimumScore: 0.1, IOUThershold: 0.3);

获取带图像的渲染框

objectModel.renderBoxesOnImage(_image!, objDetect)

#参考文献

获取带图像的渲染框

GitHub

查看 Github