TensorflowJS:TypeError:无法读取未定义的属性“获取”

时间:2019-05-08 19:19:32

标签: javascript angular typescript tensorflow tensorflow.js

我有一个angular 7应用程序,我正尝试通过遵循this示例来加载mobilenet模型。

我通过运行npm install @tensorflow/tfjs(遵循this指令)来安装tensorflowjs,并通过运行@tensorflow-models/mobilenet来安装mobilenet模型。

之后,我通过执行以下操作导入了移动网络:

import * as mobilenet from '@tensorflow-models/mobilenet';

并执行以下代码以加载模型:

mobilenet.load().then(() => {
     obs.next();
}).catch((err) => {
     console.log(err);
     console.log("ERROR");
});

但是我收到以下错误:

TypeError: Cannot read property 'fetch' of undefined
    at new e (tf-core.esm.js:17)
    at browserHTTPRequest (tf-core.esm.js:17)
    at httpRequestRouter (tf-core.esm.js:17)
    at tf-core.esm.js:17
    at Array.forEach (<anonymous>)
    at Function.e.getHandlers (tf-core.esm.js:17)
    at Function.e.getLoadHandlers (tf-core.esm.js:17)
    at Object.getLoadHandlers (tf-core.esm.js:17)
    at e.findIOHandler (tf-converter.esm.js:17)
    at e.<anonymous> (tf-converter.esm.js:17)

有人知道是什么问题吗?

1 个答案:

答案 0 :(得分:0)

我发现问题是我的packade.json上的@ tensorflow / tfs和@ tensorflow / tfjs-core版本不同。

因此,我将包配置从以下位置更改:

...
"@tensorflow/tfjs": "^1.1.2",
"@tensorflow/tfjs-core": "^1.0.2",
...

收件人:

...
"@tensorflow/tfjs": "^1.1.2",
"@tensorflow/tfjs-core": "^1.1.2",
...

错误消失了。