【问题标题】:Uncaught (in promise) TypeError: d is not a function - tensorflow jsUncaught (in promise) TypeError: d is not a function - tensorflow js
【发布时间】:2022-10-15 09:34:18
【问题描述】:

我正在尝试使用 tensorflow js 进行预测,但是当我尝试预测时出现以下错误:

Uncaught (in promise) TypeError: d is not a function 在 tfjs@latest:17:162006 在 tfjs@latest:17:159769 在 e.t.scopedRun (tfjs@latest:17:159898) 在 e.t.tidy (tfjs@latest:17:159666) 在 n (tfjs@latest:17:161982) 在 tfjs@latest:17:162468 在 e.t.scopedRun (tfjs@latest:17:159898) 在 e.t.runKernelFunc (tfjs@latest:17:162190) 在 slice_ (slice.js:177:17) 在切片 (operation.js:45:22)

这是我的 JavaScript 代码:

<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>

谢谢你的帮助!

【问题讨论】:

    标签: javascript tensorflow.js


    【解决方案1】:

    这个问题解决了吗??我面临同样的问题

    【讨论】:

      猜你喜欢
      • 2017-04-13
      • 2020-03-17
      • 2020-01-06
      • 2021-03-10
      • 2021-09-30
      • 2020-12-22
      • 2019-06-15
      • 2017-07-20
      • 1970-01-01
      相关资源
      最近更新 更多