I am using on my iobroker on node.js tensorflow-models/coco-ssd'. How do i have to load the image?
When i do it like i do, i get an error: Error: pixels passed to tf.browser.fromPixels() must be either an HTMLVideoElement, HTMLImageElement, HTMLCanvasElement, ImageData in browser, or OffscreenCanvas,
This is my code:
const cocoSsd = require('@tensorflow-models/coco-ssd');
init();
function init() {
(async () => {
// Load the model.
const model = await cocoSsd.load();
// Classify the image.
var image = fs.readFileSync('/home/iobroker/12-14-2020-tout.jpg');
// Classify the image.
const predictions = await model.detect(image);
console.log('Predictions: ');
console.log(predictions);
})();
}
The error message you are seeing in this case is accurate.
First, in this part, you are initializing
image
with a file string / Buffer instance.Then, you are passing it to
model.detect()
:The issue is that
model.detect()
is actually expecting an HTML image/video/canvas element. Per the @tensorflow-models/coco-ssd Object detection docs:It won't work on a Node server env, as stated by the same document:
However, you can follow the steps like the ones of this guide, that shows how to achieve your goal of running it on a Node server.
Example below: