Skip to content

Get variable is not initialised error #31

@Heidar-An

Description

@Heidar-An

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions