简体   繁体   English

tensorflow.js bodypix model 不工作并且没有给出任何错误

[英]tensorflow.js bodypix model not working and not giving any error

I am creating a simple body segmenting html following this我正在创建一个简单的身体分割 html以下

I have tried:我努力了:

  <body> 
       <!-- Load TensorFlow.js --> 
       <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@0.13.3"></script> 
       <!-- Load BodyPix -->
       <script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/body-pix"></script> 
           bodypix.load().then(function(net) {
               // BodyPix model loaded
           });
       </script>
   </body>
</html>

With this script:使用此脚本:


// load the BodyPix model from a checkpoint
const net = await bodyPix.load();

// arguments for estimating person segmentation.
const outputStride = 16;
const segmentationThreshold = 0.5;

const personSegmentation = await net.estimatePersonSegmentation(imageElement, outputStride, segmentationThreshold);

It works fine giving no error, but the problem is that it is not detecting person from even a simple image.它工作正常,没有错误,但问题是它甚至无法从简单的图像中检测到人。 I have tried this link for a demo, using an image given with the source code but even there it is masking the whole image not detecting any body returning an uint8clamped array full of only zeroes the same model works in my mobile.我已经尝试使用此链接进行演示,使用源代码给出的图像,但即使在那里它也掩盖了整个图像,但没有检测到任何返回 uint8clamped 数组的主体,该数组仅包含零,相同的 model 在我的手机中工作。 Is it a problem with my pc.是不是我电脑的问题。 It is i7 2600 3.7ghz是i7 2600 3.7ghz

NOTE- I have no gpu注意-我没有 gpu

The Error错误

Actually the error is that by default tensorflow uses webGL backend.实际上错误是默认情况下 tensorflow 使用 webGL 后端。 If you dont have a GPU then it will crash如果你没有 GPU 那么它会崩溃

The Solution解决方案

note- this solution is for node js but you can use similar concept with script tags also注意-此解决方案适用于节点 js,但您也可以将类似的概念与脚本标签一起使用

To solve the problem you have to at first import @tensorflow/tfjs or @tensorflow/tfjs-core or @tensorflow/tfjs-node and then set its backend as cpu (or tensorflow if you are using @tensorflow/tfjs-node) Refer to the below script要解决此问题,您必须首先导入 @tensorflow/tfjs 或 @tensorflow/tfjs-core 或 @tensorflow/tfjs-node ,然后将其后端设置为 cpu(或 tensorflow,如果您使用的是 @tensorflow/tfjs-node)参考到下面的脚本

//main.js file, works well with webpack
import * as tf from '@tensorflow/tfjs-core'
import * as bodypix from '@tensorflow-models/body-pix'

tf.setBackend('cpu')

//now you can load bodypix or any model

For documentation refer here有关文档,请参阅此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM