I'm trying to know if there is some face on an image and so I'm using tensorflow JS with blazeface model. But after getting the code an error appear:
Error: No backend found in registry.
at Engine.getSortedBackends (/home/saren/project/spark/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:2928:19)
at Engine.initializeBackendsAndReturnBest (/home/saren/project/spark/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:2937:35)
at Engine.get [as backend] (/home/saren/project/spark/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:2743:31)
at Engine.makeTensor (/home/saren/project/spark/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:3268:35)
at makeTensor (/home/saren/project/spark/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:4087:19)
at tensor (/home/saren/project/spark/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:4136:12)
at Object.decodeWeights (/home/saren/project/spark/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:4400:27)
at GraphModel.loadSync (/home/saren/project/spark/node_modules/@tensorflow/tfjs-converter/dist/tf-converter.node.js:7410:34)
at GraphModel.<anonymous> (/home/saren/project/spark/node_modules/@tensorflow/tfjs-converter/dist/tf-converter.node.js:7385:52)
at step (/home/saren/project/spark/node_modules/@tensorflow/tfjs-converter/dist/tf-converter.node.js:77:23)
This is my code (I copy past it from the documentation):
module.exports = {
blazeface: require('@tensorflow-models/blazeface'),
async detectFace(imageLink) {
const model = await this.blazeface.load();
const returnTensors = false;
const predictions = await model.estimateFaces(imageLink, returnTensors);
if (predictions.length > 0) {
for (let i = 0; i < predictions.length; i++) {
const start = predictions[i].topLeft;
const end = predictions[i].bottomRight;
const size = [end[0] - start[0], end[1] - start[1]];
// Render a rectangle over each detected face.
ctx.fillRect(start[0], start[1], size[0], size[1]);
}
}
}
}
Remember that the error came from the following line const model = await this.blazeface.load();
So a lot of people are talking about the version so this is an exemple of my package.json
"dependencies": {
"@tensorflow-models/blazeface": "0.0.6",
"@tensorflow/tfjs": "^3.0.0",
"@tensorflow/tfjs-backend-cpu": "^3.0.0",
"@tensorflow/tfjs-backend-webgl": "^3.0.0",
"@tensorflow/tfjs-converter": "^3.0.0",
"@tensorflow/tfjs-core": "^3.0.0"
}
I'm using Node version 14.8.0 and npm version 6.14.7. This code should work on a server and so I don't want it to work in front.
Seems that you can do two things.
Install @tensorflow/tfjs-node and use tf: require("@tensorflow/tfjs-node"),
Or you can use this.tf.getBackend();
(even with this tf: require("@tensorflow/tfjs")
)