未处理的拒绝(错误):model.execute(dict) 中提供的 dict['ImageTensor'] 的 dtype 必须为 int32,但为 float32
Unhandled Rejection (Error): The dtype of dict['ImageTensor'] provided in model.execute(dict) must be int32, but was float32
我尝试 运行 deep lab 模型 javascript 在视频上,但我收到错误未处理的拒绝(错误):提供的 dict['ImageTensor'] 的数据类型在 model.execute(dict) 中必须是 int32,但是是 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
问题出在tensorflow版本上,请执行以下操作:
卸载当前版本
npm uninstall @tensorflow/tfjs
安装低版本1.3.1
npm install @tensorflow/tfjs@1.3.1
Deeplab 似乎无法在更高版本上运行
我尝试 运行 deep lab 模型 javascript 在视频上,但我收到错误未处理的拒绝(错误):提供的 dict['ImageTensor'] 的数据类型在 model.execute(dict) 中必须是 int32,但是是 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
问题出在tensorflow版本上,请执行以下操作: 卸载当前版本
npm uninstall @tensorflow/tfjs
安装低版本1.3.1
npm install @tensorflow/tfjs@1.3.1
Deeplab 似乎无法在更高版本上运行