i'm trying to do a prediction with tensorflow js, but when I try to predict have de following error:
Uncaught (in promise) TypeError: d is not a function at tfjs@latest:17:162006 at tfjs@latest:17:159769 at e.t.scopedRun (tfjs@latest:17:159898) at e.t.tidy (tfjs@latest:17:159666) at n (tfjs@latest:17:161982) at tfjs@latest:17:162468 at e.t.scopedRun (tfjs@latest:17:159898) at e.t.runKernelFunc (tfjs@latest:17:162190) at slice_ (slice.js:177:17) at slice (operation.js:45:22)
This is my javascript code:
<script>
async function inicializar() {
alert("estoy en inicialize");
document.getElementById('prediccion').addEventListener('click', () => predecir());
};
async function predecir() {
alert("estoy en predecir"); //Mensaje para chequear que entre aca
const modelo = await tf.loadLayersModel('trained-model/model.json');
const canvas = document.getElementById('output');
alert(canvas);// Mensaje para ver si lee canvas como elemento HTML
let tensorImg = tf.browser.fromPixels(canvas).resizeNearestNeighbor([150, 150]).toFloat().expandDims();
alert("pasa esto"); //Mensaje para chequear que entre aca
alert(tensorImg); //Mensaje para ver si lee el tensor de la imagen
prediction = modelo.predict(tensorImg).data(); //Aca me da error!!!!! TypeError: d is not a function
alert("pase hasta aca"); //Mensaje para chequear que entre aca, pero no llega
var respuesta;
if (prediction <= .5) {
respuesta = "Gato";
} else {
respuesta = "Perro";
}
document.getElementById("prediccion").innerHTML = respuesta;
};
inicializar()
</script>
Thanks for your help!