Cocoa detector and classification with Yolov5 and flutter
Send message if you want the full code
Testing
Results
- Confusion matrix
- Others
flutter_pytorch
- flutter plugin to help run pytorch lite models classification for example yolov5 doesn’t give support for yolov7
- ios support (can be added following this https://github.com/pytorch/ios-demo-app) PR will be appreciated
Getting Started
Usage
preparing the model
- object detection (yolov5)
!python export.py --weights "the weights of your model" --include torchscript --img 640 --optimize
example
!python export.py --weights yolov5s.pt --include torchscript --img 640 --optimize
Installation
To use this plugin, add pytorch_lite
as a dependency in your pubspec.yaml file.
Create a assets
folder with your pytorch model and labels if needed. Modify pubspec.yaml
accordingly.
assets:
- assets/models/model_objectDetection.torchscript
- assets/labels_objectDetection.txt
Run flutter pub get
For release
- Go to android/app/build.gradle
- Add those next lines in the release config
shrinkResources false
minifyEnabled false
example
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 the library
import 'package:flutter_pytorch/flutter_pytorch.dart';
Load model
Either classification model:
ObjectDetection model:
```dart
ModelObjectDetection objectModel = await FlutterPytorch.loadObjectDetectionModel(
"assets/models/yolov5s.torchscript", 80, 640, 640,
labelPath: "assets/labels/labels_objectDetection_Coco.txt");
Get object detection prediction for an image
List<ResultObjectDetection?> objDetect = await _objectModel.getImagePrediction(await File(image.path).readAsBytes(),
minimumScore: 0.1, IOUThershold: 0.3);
Get render boxes with image
objectModel.renderBoxesOnImage(_image!, objDetect)
#References
- Code used the same strucute as the package https://pub.dev/packages/pytorch_mobile
- While using the updated code from https://github.com/pytorch/android-demo-app
Get render boxes with image