BodyPix-错误:在注册表中找不到后端

问题描述

我正在尝试通过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();

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...