【问题标题】:Unhandled Rejection (Error): The dtype of dict['ImageTensor'] provided in model.execute(dict) must be int32, but was float32未处理的拒绝(错误):model.execute(dict)中提供的dict['ImageTensor']的dtype必须是int32,但是是float32
【发布时间】:2021-01-15 16:48:54
【问题描述】:

我尝试在此处的视频上运行 deep lab model javascript 但我收到错误 Unhandled Rejection (Error): The dtype of dict['ImageTensor'] provided in model.execute(dict) must be int32, but was float32 ,这是我的代码

import React,{useEffect,useRef} from "react";
import Webcam from "react-webcam";

import * as tf from "@tensorflow/tfjs"
import * as deeplab from "@tensorflow-models/deeplab"


 
const Webcamera = () => {
    const webcamref = useRef(null)

    const loadModel = async () => {
        const modelName = 'ade20k';   // set to your preferred model, either `pascal`, `cityscapes` or `ade20k`
        const quantizationBytes = 2;  // either 1, 2 or 4
        const model = await deeplab.load({base: modelName, quantizationBytes});

        

        setInterval(() => {
            detect(model)
        },100)
      };

      const detect = async (model) => {
          if(typeof webcamref.current!=undefined && webcamref.current!=null && webcamref.current.video.readyState === 4 ){
              const video = webcamref.current.video
              const videowidth = webcamref.current.video.videowidth
              const videoheight = webcamref.current.video.videoheight

              webcamref.current.video.videowidth = videowidth
              webcamref.current.video.videoheight = videoheight
              

              model.segment(video)

              
          }
      }

      useEffect(()=>{loadModel()}, []);
      

return <Webcam ref={webcamref}/>
}

export default Webcamera

【问题讨论】:

    标签: reactjs machine-learning tensorflow.js


    【解决方案1】:

    问题是 tensorflow 版本,请执行以下操作: 卸载当前版本

    npm uninstall @tensorflow/tfjs
    

    安装低版本 1.3.1

    npm install @tensorflow/tfjs@1.3.1
    

    Deeplab 似乎不适用于更高版本

    【讨论】:

      猜你喜欢
      • 2020-06-01
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多