无法在Tensorflow.js中加载冻结的模型

时间:2018-10-04 07:38:11

标签: javascript tensorflow.js

我尝试加载转换后的Tensorflow模型,但控制台显示以下错误:

版本:

"dependencies": {
    "@tensorflow-models/posenet": "0.1.2",
    "@tensorflow/tfjs": "0.11.4",
    "@tensorflow/tfjs-converter": "^0.6.1",
    "asyncawait": "^1.0.7",
    "stats.js": "^0.17.0"
  }

代码:

import * as tf from '@tensorflow/tfjs';
import {loadFrozenModel} from '@tensorflow/tfjs-converter';

const MODEL_URL = 'faster_rcnn/web_model/tensorflowjs_model.pb';
const WEIGHTS_URL = 'faster_rcnn/web_model/weights_manifest.json';

const model =(async () => {
    await loadFrozenModel(MODEL_URL, WEIGHTS_URL)})();

错误:enter image description here

我将模型放入Google云端硬盘:

https://drive.google.com/file/d/1yNIC9TD1MWzJyI3ewnJCmM1bmTAYC_1E/view?usp=sharing

请帮助。

谢谢!

1 个答案:

答案 0 :(得分:0)

您必须将存储类型传递给loadFrozenModel()。在您的情况下为:file:///

代码中的另一个问题是,立即调用的异步函数不返回任何内容,因此您的模型变量保持未定义状态。

要同时解决这两个问题:

(async () => {
    const model = loadFrozenModel('file:///' + MODEL_URL, 'file:///' + WEIGHTS_URL);
    //Now you can only use 'model' in here.
})();