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

could not invoke TfliteReactNative.loadModel is null models/mobilenet_v1_1.0_224.tflite #12

Open
marikani opened this issue Sep 5, 2019 · 13 comments

Comments

@marikani
Copy link

marikani commented Sep 5, 2019

No description provided.

@marikani
Copy link
Author

marikani commented Sep 5, 2019

I am facing this problem.

@marikani marikani changed the title could not invoke Tflite React Native.load Model could not invoke TfliteReactNative.loadModel is null models/mobilenet_v1_1.0_224.tflite Sep 5, 2019
@hinhinvn1111111
Copy link

Hi guy. i already sovle this problem( see reneweb/react-native-tensorflow#34).

  1. Run yarn add --dev metro metro-core
  2. Run yarn install
  3. Replace file metro.config.js
    module.exports = {
    resolver: {
    assetExts: ['pb', 'txt', 'jpg']
    }
    }

@Macilias
Copy link

really? TFLite ending is .tflite not .pb so how could this one help?

@Macilias
Copy link

Macilias commented Sep 16, 2019

I have also the same issue:

Could not invoke TfliteREactNative.loadModels
null
/path/to/my/model.tflite

This is how I initialize the model:

    async init() {
        try {
            console.log( "started initialization of TENSOR FLOW LITE" );
            let tfLite = new Tflite();
            await tfLite.loadModel( {
                model: this.props.protobuf, // required
                labels: this.props.labels,  // required
                numThreads: 1,              // defaults to 1
            } );
            this.setState( {tfLite: tfLite} );
        } catch ( err ) {
            if ( err.description === "cancelled" ) {
                console.log( "cancelled by user" );
            }
            console.error( "Got error on init(): ", err );
        }
    }

I'm passing the path to model file and labels as props. This approach is working exactly the same way for react-native-tensorflow but with a .pb file of caurse instead of an .tflite file as in this case.
I tried with putting file:// before the actual file, but didn't help.

By the way:
First I had this one:

[15:20:16] E | ReactNativeJS ▶︎ 'Got error on init(): ', { [TypeError: null is not an object (evaluating 'TfliteReactNative.loadModel')]
                             │ line: 115254,
                             │ column: 26,
                             └ sourceURL: 'http://localhost:8081/index.bundle?platform=android&dev=true&minify=false' }

but it was due of missing steps from Android part, so I'm adding it here, just in case someone else ends up in the same situation and needs quick help.

@ShaharyarMaroof
Copy link

Any updates on how to fix this? I am also getting this same error. I used the example code provided in the repo and have placed the models and labels in the android/app/src/main/assets directory as well, and in a models directory in my react-native code src.

@Macilias
Copy link

nope and the project seams not to be updated as frequently as it should to become reliable.
I suggest you check out the real deal: https://github.com/tensorflow/tfjs/tree/master/tfjs-react-native
just compare the stars

@ShaharyarMaroof
Copy link

Hey @Macilias, thanks for the suggestion will look into it as well!
I finally got it to work by the following steps:

  1. Create the assets directory in the app folder via Android Studio.
    • Open the android project in Android Studio, then click on the app folder
    • The go to File > New > Assets Folder
    • Select main as the target source set.
  2. Create a models folder in the assets directory and placed all models and labels and labels which are available in the example code.
  3. Now, when I used the example code it worked correctly.

@robsonpsdesv
Copy link

@marikani @ShaharyarMaroof
I couldn't solve it by following what you did.
Help me =/

@janithwanni
Copy link

Hey @robsonpsdesv I was able to get the model up by following these steps which are similar to the ones @ShaharyarMaroof did

  1. Make a new folder called assets in app/src/main/
  2. Place the model file (tflite and txt) on to the folder
  3. Add to android/app/build.gradle the lines from the README (I normally put it towards the end of the file)
aaptOptions {
        noCompress 'tflite'
    }
  1. And then call the loadModel function

Do let us know what your error might have been

@robsonpsdesv
Copy link

Yes @ShaharyarMaroof succecfuly, tks;)

@kad1r
Copy link

kad1r commented Nov 3, 2019

I have also the same issue:

Could not invoke TfliteREactNative.loadModels
null
/path/to/my/model.tflite

This is how I initialize the model:

    async init() {
        try {
            console.log( "started initialization of TENSOR FLOW LITE" );
            let tfLite = new Tflite();
            await tfLite.loadModel( {
                model: this.props.protobuf, // required
                labels: this.props.labels,  // required
                numThreads: 1,              // defaults to 1
            } );
            this.setState( {tfLite: tfLite} );
        } catch ( err ) {
            if ( err.description === "cancelled" ) {
                console.log( "cancelled by user" );
            }
            console.error( "Got error on init(): ", err );
        }
    }

I'm passing the path to model file and labels as props. This approach is working exactly the same way for react-native-tensorflow but with a .pb file of caurse instead of an .tflite file as in this case.
I tried with putting file:// before the actual file, but didn't help.

By the way:
First I had this one:

[15:20:16] E | ReactNativeJS ▶︎ 'Got error on init(): ', { [TypeError: null is not an object (evaluating 'TfliteReactNative.loadModel')]
                             │ line: 115254,
                             │ column: 26,
                             └ sourceURL: 'http://localhost:8081/index.bundle?platform=android&dev=true&minify=false' }

but it was due of missing steps from Android part, so I'm adding it here, just in case someone else ends up in the same situation and needs quick help.

Hello, if possible, can you please share your working code?
I'm getting same error and none of those methods are working.

@kad1r
Copy link

kad1r commented Nov 3, 2019

My solution is related with emulator. If you are using real device it works.

@sauravjmedhi
Copy link

Since the official docs do not tell us to create a 'models' directory inside the 'assets' directory, removing 'models' from the path should work.

tflite.loadModel({
  model: 'mobilenet_v1_1.0_224.tflite',// required
  labels: 'mobilenet_v1_1.0_224.txt',  // required
  numThreads: 1,                              // defaults to 1  
},

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

8 participants