问题描述
我正在尝试通过TensorFlow网站上的教程设置BodyPix,但出现以下错误
Uncaught (in promise) Error: No backend found in registry.
at Engine.getSortedBackends (engine.js:248)
at Engine.initializeBackendsAndReturnBest (engine.js:257)
at Engine.get backend [as backend] (engine.js:94)
at Engine.makeTensor (engine.js:556)
at makeTensor (tensor_ops_util.js:57)
at tensor (tensor.js:48)
at Module.decodeWeights (io_utils.js:212)
at GraphModel.loadSync (graph_model.js:118)
at GraphModel.load (graph_model.js:102)
at async loadGraphModel (graph_model.js:348)
我尝试安装了一些我认为可能会有用的软件包,但是我真的不确定现在该怎么做。。感谢我能得到的任何输入。
package.json
"dependencies": {
"@babel/core": "^7.11.1","@babel/preset-env": "^7.11.0","@tensorflow-models/body-pix": "^2.0.5","@tensorflow/tfjs": "^2.3.0","@tensorflow/tfjs-converter": "^2.3.0","@tensorflow/tfjs-core": "^2.3.0","@tensorflow/tfjs-node-gpu": "^2.3.0"
},"devDependencies": {
"babel-loader": "^8.1.0","webpack-dev-server": "^3.11.0","webpack": "^4.44.1","webpack-cli": "^3.3.12"
}
index.js
import * as bodyPix from '@tensorflow-models/body-pix';
const img = document.getElementById('image');
async function loadAndPredict() {
const net = await bodyPix.load(/** optional arguments,see below **/);
/**
* One of (see documentation below):
* - net.segmentPerson
* - net.segmentPersonParts
* - net.segmentMultiPerson
* - net.segmentMultiPersonParts
* See documentation below for details on each method.
*/
const segmentation = await net.segmentPerson(img);
console.log(segmentation);
}
loadAndPredict();
解决方法
我使用的是body-pix
的相同版本,遇到了完全相同的问题。我通过从@tensorflow/tfjs
包中导入模块来解决了该问题。似乎必须导入这些模块才能注册后端。您可能必须执行以下操作才能解决此问题:
import * as tf from '@tensorflow/tfjs';
...
console.log('Using TensorFlow backend: ',tf.getBackend());
loadAndPredict();