I am trying to load a custom model trained on TeachableMachine into my React native app, the mobilenet model does work, but when I try to load my own custom model it stays undefined and it won't resolve the loading phase of the model.
Relevant Code:
import React, { useEffect, useState } from "react";
import { ActivityIndicator, Text } from "react-native";
import { MainContainer } from "../utils/styles";
import * as tf from "@tensorflow/tfjs";
import { fetch } from "@tensorflow/tfjs-react-native";
import * as jpeg from "jpeg-js";
// import * as mobilenet from "@tensorflow-models/mobilenet";
...
const getPrediction = async () => {
try {
await tf.ready();
// const model = await mobilenet.load();
const model = await tf.loadLayersModel(
"https://teachablemachine.withgoogle.com/models/ULiD4t_yQ/model.json"
);
const response = await fetch(image, {}, { isBinary: true });
const rawImageData = await response.arrayBuffer();
const imageTensor = await imageToTensor(rawImageData);
const prediction = await model.classify(imageTensor);
setPrediction(prediction);
setIsLoading(false);
} catch (e) {
console.log(e);
}
};
useEffect(() => {
getPrediction();
}, []);
...
Teachablemachine provides free cloud hosting of the model, and by tutorials I've seen online tf.loadLayersModel should work with a browser link linked to my model.json.
Error:
model.classify is not a function. (In 'model.classify(imageTensor)', 'model.classify' is undefined)
I tried to load the files locally and pass them to the loadLayersModel function but it doesn't work as well.