Skip to content

Instantly share code, notes, and snippets.

@jeffcrouse
Created January 21, 2022 16:26
Show Gist options
  • Save jeffcrouse/750f26afdaedb4d6cd0a523ed591dccc to your computer and use it in GitHub Desktop.
Save jeffcrouse/750f26afdaedb4d6cd0a523ed591dccc to your computer and use it in GitHub Desktop.
const tf = require('@tensorflow/tfjs-node-gpu');
const bodyPix = require('@tensorflow-models/body-pix');
const fs = require('fs');
// https://www.npmjs.com/package/@tensorflow-models/body-pix
async function classify() {
tf.setBackend('tensorflow')
const net = await bodyPix.load({
architecture: 'MobileNetV1',
outputStride: 16,
multiplier: 0.75,
quantBytes: 2
});
const imageBuffer = await fs.promises.readFile("ppl01.jpg");
const image = tf.node.decodeImage(imageBuffer);
var start = Date.now();
const segmentation = await net.segmentMultiPerson(image, {
flipHorizontal: false,
internalResolution: 'medium',
segmentationThreshold: 0.7,
maxDetections: 10,
scoreThreshold: 0.2,
nmsRadius: 20,
minKeypointScore: 0.3,
refineSteps: 10
});
const millis = Date.now() - start;
//console.log(segmentation);
console.log(millis +" milliseconds");
}
try {
classify();
} catch(e) {
console.log(e);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment