Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get variable is not initialised error #31

Open
Heidar-An opened this issue Aug 1, 2023 · 0 comments
Open

Get variable is not initialised error #31

Heidar-An opened this issue Aug 1, 2023 · 0 comments

Comments

@Heidar-An
Copy link

I'm trying to use your flutter package for a custom model but I get that my model is not initialised. Is this a regular occurrence?

Let me show you some of my code:

import 'package:pytorch_mobile/pytorch_mobile.dart';
import 'package:pytorch_mobile/model.dart';

I've put pytorch_mobile in my dependencies and added my assets:

  assets:
    - assets/models/[fine-tuning_0.pt](http://fine-tuning_0.pt/)
    - assets/models/

I put both the actual asset and the directory because it wasn't working, so i just put both, I've tried the combinations and it doesn't work.

@override
  void initState() {
       loadPytorchModel().whenComplete(() => log("THIS IS DONE"));

Future<void> loadPytorchModel() async {
    mobileNetModel =
        await PyTorchMobile.loadModel('assets/models/[fine-tuning_0.pt](http://fine-tuning_0.pt/)');
  }

 Future<void> takePicture() async {
    image = ....
    // Ensure that model has been initialised
    log("this works...");
    if (mobileNetModel == null) {
      await loadPytorchModel();
    }
    List? prediction = await mobileNetModel!
        .getImagePredictionList(image, decodedImage.width, decodedImage.height);

If I put the if statement checking if the model is null, then nothing happens, if I remove it, I get "mobileNetModel" is uninitialised.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant