Priyanka Dhumane
Priyanka Dhumane

Reputation: 41

TensorflowJS - React Native - Error predicting from tensor image

I'm trying to get a keras model I converted to tensorflowJS to work in react native but getting the error in predicting the image tensor.

I have trained a custom tensorflow keras model and converted the keras h5 model to JavaScript JSON model. In React Native project, I have used expo camera with tensorflow to capture the image to predict the damage on the captured image.

Here, I have included the versions use in my projects, commands used to convert and predict the model.

Versions used

Command used to convert Keras h5 to JS json :

tensorflowjs_converter --input_format=keras --weight_shard_size_bytes=419430400 --quantize_float16=* /path/to/model.h5 /path/to/output

Creating and using Layers model in RN

 // Load layers model using model json and weights file
 const models = await tf.loadLayersModel(bundleResourceIO(modelJSON, weights));

Logs of Capturing Image via expo camera and cameraWithTensors

 LOG  imageAsTensors:  {"kept":false,"isDisposedInternal":false,"shape":[224,224,3],"dtype":"int32","size":150528,"strides":[672,3],"dataId":{"id":670},"id":980,"rankType":"3"}
 LOG  imageTensorReshaped:  {"kept":false,"isDisposedInternal":false,"shape":[1,224,224,3],"dtype":"int32","size":150528,"strides":[150528,672,3],"dataId":{"id":670},"id":981,"rankType":"4","scopeId":408}

Predicting image tensor using model

try {
      // predict against the model
      const output = await models.predict(imageTensorReshaped, { batchSize: 1 });
      return output.dataSync();
    } catch (error) {
      console.log('Error predicting from tensor image', error);
    }

Receiving the below error in catch Error predicting from tensor image [TypeError: null is not an object (evaluating 'opHandler.clone')]

Expectations : Prediction result array

Upvotes: 2

Views: 516

Answers (1)

janfar
janfar

Reputation: 11

The issue is that the setOpHandler function is not being called in the tfjs-node files in the package. You can check out this issue on github here! for a temporary fix using the provided patch files

Upvotes: 1

Related Questions