且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用 Tensorflow.js 运行对象检测

更新时间:2023-12-02 18:42:04

终于找到了问题所在,它与输入框的大小有关.

Finally, I could figure out the problem and it was related to the size of an input frame.

SSD 模型需要 [1,300,300,3] 图像/帧的形状作为输入.我在我的代码中添加了这个并得到了解决方案.使用以下行(在 inference.html 中),我们可以将 (300,300,3) 形状的图像作为模型的输入:

SSD model needs shape of [1,300,300,3] image/frame as input. I added this in my code and got the solution. Using the following line (in inference.html), we can feed (300,300,3) shape of image as an input to the model:

 <img id="img" src="257.jpg" width="300" height="300"/>

index.js 中使用以下几行:

Using the following lines in index.js:

 tf_img = tf_img.expandDims(0);
 console.log(tf_img.shape)  // Image dimension is  [1, 300, 300, 3]

我们得到SSD需要的[1,300,300,3]的图像形状.

We obtain image shape of [1,300,300,3] which is needed by SSD.