reneweb / react-native-tensorflow

A TensorFlow inference library for react native
Apache License 2.0
358 stars 59 forks source link

Tensorflow throw error after build .apk and using on real device #15

Closed taeyzzz closed 6 years ago

taeyzzz commented 6 years ago

I'm using tensorflow to detect data if true or false. It work perfectly on emulator device but after I generate .apk and run on real device. It always cause the error. below is my code

const tfImageRecognition = new TfImageRecognition({
      model: require('path/to/model.pb'),
      labels: require('path/to/label.txt'),
      imageMean: 0, // Optional, defaults to 117
      imageStd: 255 // Optional, defaults to 1
    })
    tfImageRecognition.recognize({
      image: this.state.imagePath,
      inputName: "input_1", //Optional, defaults to "input"
      inputSize: 224, //Optional, defaults to 224
      outputName: "k2tfout_0", //Optional, defaults to "output"
      maxResults: 3, //Optional, defaults to 3
      threshold: 0.1 //Optional, defaults to 0.1
    })
      .then(results => {
        console.warn('done');
        ToastAndroid.show('tensowflow done', ToastAndroid.SHORT);
      })
      .catch(err => {
        ToastAndroid.show(err, ToastAndroid.SHORT);
        console.error('errorrrrrrrrrrrrrrrrrrrrr');
        console.error(err);
      })

when function tfImageRecognition.recognize was called it always throw error to .catch

reneweb commented 6 years ago

Can you post the actual error message that you get in the catch clause?

alextsg commented 6 years ago

@reneweb I've been encountering the same thing, getting Error: Could not load resource when running off the .apk and not metro bundler.

reneweb commented 6 years ago

I've had a look and there was an issue when loading the resources in release mode. I've just released version 0.1.4 which should fix this issue.

taeyzzz commented 6 years ago

i've tried with new version. it still always call in catch when i build cd android && ./gradlew assembleRelease

and this is my code

` const tfImageRecognition = new TfImageRecognition({ model: require('../../model.pb'), labels: require('../../label.txt'), imageMean: 117, // Optional, defaults to 117 imageStd: 1 // Optional, defaults to 1 })

tfImageRecognition.recognize({
  image: this.state.imagePath,
  inputName: "input_1", //Optional, defaults to "input"
  inputSize: 224, //Optional, defaults to 224
  outputName: "k2tfout_0", //Optional, defaults to "output"
  maxResults: 3, //Optional, defaults to 3
  threshold: 0.1, //Optional, defaults to 0.1
}).then(results => {
  results.forEach(result => {
    console.log('result -------------------');
    console.log(
      result.id, // Id of the result
      result.name, // Name of the result
      result.confidence // Confidence value between 0 - 1
    )
    alert(result.name) //when run with metro bundler. it will be working good
  })
})
.catch(err => {
  alert('tensorflow error') // always alert when i build apk and try in real device
  console.log('errorrrrrrrrrrrrrrrrrrrrr');
  console.log(err);
})

` and this is version that i've tried

"react-native-tensorflow": "^0.1.6"

Thank you @reneweb