abdelaziz-mahdy / pytorch_lite

flutter package to help run pytorch lite models classification and YoloV5 and YoloV8.
MIT License
49 stars 18 forks source link

Collision with pytorch_mobile #56

Closed KonstiDE closed 8 months ago

KonstiDE commented 8 months ago

Hello,

currently, pytorch_lite ^4.2.2 collides with a plugin for raw predictions, pytorch_mobile ^0.2.2 in the method channel. When importing pytorch_lite you get:

E/flutter (20555): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method loadModel on channel pytorch_mobile)
E/flutter (20555): #0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:308:7)
E/flutter (20555): <asynchronous suspension>
E/flutter (20555): #1      PyTorchMobile.loadModel (package:pytorch_mobile/pytorch_mobile.dart:15:17)
E/flutter (20555): <asynchronous suspension>
E/flutter (20555): #2      _CameraWalkthroughScreen.doStuff (package:wunderkint/presentation/screens/camera/camera_walkthrough_screen.dart:52:19)
E/flutter (20555): <asynchronous suspension>

Does flutter override some method named "loadMethod" in the channel? Or can I somehow also make raw predictions with pytorch_lite?

I uploaded (get my model) my model that I load with pytorch_mobile, would rather do it with pytorch_lite or make both libs compatable...

abdelaziz-mahdy commented 8 months ago

there should be no conflicts, and this package has all of the features in pytorch_mobile if i remember correctly, more over just general debugging steps

after adding pytorch_lite or pytorch_mobile did you restart the app ?

KonstiDE commented 8 months ago

Yes, also with flutter clean, then flutter pub get and then run again

abdelaziz-mahdy commented 8 months ago

i dont know what may be the cause of this since its not from my side :( but let me know if there is a feature not provided in my package maybe i can implement it

KonstiDE commented 8 months ago

We'll the goal is to get just a simple probability prediction with a custom model as I provided in the question. For pytorch_mobile, I would go:

File file = await getFile("0518.png");
Model model = await PyTorchMobile.loadModel("assets/models/traced_enet.pt");
List<dynamic>? prediction = await model.getImagePredictionList(file, 224, 224);
List<int> intlist = List.of(prediction!.map((e) => e > 0.5 ? 1 : 0));

This loads a picture, loads the model, makes a prediction and thresholds it afterwards. However, I cannot load the model into pytorch_lite, since it is not yolo related and either a classification nor an object detection model...

abdelaziz-mahdy commented 8 months ago

But it's a classification model? It does take image as an input correct? If that's the case you can get the raw output of the model

The package is not limited to yolo or classification if the model accepts an image this package will work,

The only limition is sending list of values and getting the return of it (this is not supported)

KonstiDE commented 8 months ago

Mb, when try to load the model I had not saved it with ._save_for_lite_interpreter, otherwise it did not work.

Thank you for the fast support!