how to use teachable machine model in react native expo

Viewed 462

I'm using teachable machine exported model.

const modelJson = require("./assets/models/model.json");
const modelWeights = require("./assets/models/weights.bin");


useEffect(() => {
    let checkTf = async () => {
      await tf.ready();
      const model = await tf.loadLayersModel(bundleResourceIO(modelJson, modelWeights));
      setModel(model);
      setDisplayText("loaded Models");
      setTfReady(true);
    };
    checkTf();
  }, []);

Loaded model in predicting image async function:

const imageTensor = images.next().value;
const prediction = (await model.predict())[0]; //ERROR
const highestPropPred = prediction[0];

can't loading prediction this error:

[Unhandled promise rejection: Error: Error when checking : expected input_1 to have 4 dimension(s), but got array with shape [200,152,3]]
2 Answers

I recommend you try reshape the image to [1 ,200 , 150, 3] using reshape function.

I'm not sure, but as I aware, you should eject your expo app to can use tf for RN or use bare RN project.

Related