To get help from the community, we encourage using Stack Overflow and the tensorflow.js
tag.
not in the browser, using Node command
Describe the problem or feature requestI am using tensorflow.js of coco-SSD for mobilenet v2 when I am using the pre-trained model [coco-ssd] it's working perfectly fine, see the below code
const tfnode = require('@tensorflow/tfjs-node');
const cocoSsd = require('./coco-ssd.js');
const fs = require('fs');
const readImage = path => {
const imageBuffer = fs.readFileSync(path);
const tfimage = tfnode.node.decodeImage(imageBuffer);
return tfimage;
}
const objectDetection = async path => {
const image = readImage(path);
const loadlModelPromise = await cocoSsd.load({base: "mobilenet_v2"})
const result = await loadlModelPromise.detect(image);
console.log('Classification Results:', result);
}
objectDetection(process.argv[2]);
while calling the above code node filename.js ./testImage.png
it gives the desired result.
Now I have a custom trained coco-ssd model which i have converted to tensorflow.js format using the below command
**tensorflowjs_converter --input_format=tf_saved_model --output_node_names='num_detections,detection_boxes,detection_scores,detection_classes' --signature_name=serving_default --saved_model_tags=serve ./saved_model ./
**
once i have the converted model.json i wrote the below code for inference on the custom converted model.
const tfnode = require('@tensorflow/tfjs-node');
const cocoSsd = require('./coco-ssd.js');
const fs = require('fs');
const readImage = path => {
const imageBuffer = fs.readFileSync(path);
const tfimage = tfnode.node.decodeImage(imageBuffer);
return tfimage;
}
const objectDetection = async path => {
const image = readImage(path);
const modelUrl = 'file:///Users/xx/model.json'
const loadlModelPromise = await cocoSsd.load({base: "mobilenet_v2",modelUrl: modelUrl})
const result = await loadlModelPromise.detect(image);
console.log('Classification Results:', result);
}
objectDetection(process.argv[2]);
now when I am running the above code node fileName.js ./testImage.png
getting the bellow error
(node:32504) UnhandledPromiseRejectionWarning: Error: Tensor must have a shape comprised of positive integers but got shape [100,]. at assert (C:\Users\xx\tfJs\node_modules@tensorflow\tfjs-core\dist\util.js:105:15) at C:\Users\xx\tfJs\node_modules@tensorflow\tfjs-core\dist\util.js:646:9 at Array.forEach () at Object.assertNonNegativeIntegerDimensions (C:\Users\xx\tfJs\node_modules@tensorflow\tfjs-core\dist\util.js:645:11) at makeTensor (C:\Users\xx\tfJs\node_modules@tensorflow\tfjs-core\dist\ops\tensor_ops.js:73:16) at Object.tensor2d (C:\Users\xx\tfJs\node_modules@tensorflow\tfjs-core\dist\ops\tensor_ops.js:189:12) at C:\Users\xx\tfJs\tensorflowJs Classifier\coco-ssd.js:17:7039 at C:\Users\xx\tfJs\node_modules@tensorflow\tfjs-core\dist\engine.js:388:22 at Engine.scopedRun (C:\Users\xx\tfJs\node_modules@tensorflow\tfjs-core\dist\engine.js:398:23) at Engine.tidy (C:\Users\xx\tfJs\node_modules@tensorflow\tfjs-core\dist\engine.js:387:21)
please help :-)