2

I am creating a simple body segmenting html following this

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. Is it a problem with my pc. It is i7 2600 3.7ghz

NOTE- I have no gpu

yudhiesh
  • 6,383
  • 3
  • 16
  • 49
hemant kumar
  • 545
  • 6
  • 19

1 Answers1

1

The Error

Actually the error is that by default tensorflow uses webGL backend. If you dont have a GPU then it will crash

The Solution

note- this solution is for node js but you can use similar concept with script tags also

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

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

hemant kumar
  • 545
  • 6
  • 19