bodypix-background/server.js

33 lines
686 B
JavaScript
Raw Normal View History

const zmq = require('zeromq');
const tf = require('@tensorflow/tfjs-node');
const bodyPix = require('@tensorflow-models/body-pix');
const {decodeJpeg} = require('./decode_image');
let net = null;
async function load() {
net = await bodyPix.load({
architecture: 'MobileNetV1',
outputStride: 16,
multiplier: 0.5,
quantBytes: 2
});
}
async function run() {
const sock = new zmq.Reply;
await sock.bind('ipc:///tmp/bodypix');
console.log("Bounded to ipc:///tmp/bodypix");
for await (const [msg] of sock) {
const image = decodeJpeg(msg)
const segmentation = await net.segmentPerson(image);
await sock.send(segmentation.data);
2020-05-03 16:03:48 -04:00
tf.dispose(image)
}
}
load();
run();