【问题标题】:node-fetch error while loading trained model in tensorflow.js在 tensorflow.js 中加载训练模型时节点获取错误
【发布时间】:2021-01-10 18:05:43
【问题描述】:

在训练我的 tensorflow 模型后,我将其转换为 tensorflow.js 要求的 json 格式。但是,当我尝试使用 javascript 加载此模型时,我收到 node-fetch 错误。

这是我的代码:

const tf = require("./tf.min.js");
(async function () {
  const modelURL = "model_js/model.json";
  const model = await tf.loadLayersModel(modelURL);
  model.summary();
})();

完整的错误日志:

(node:35092) UnhandledPromiseRejectionWarning: Error: Cannot find module 'node-fetch'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
    at Function.Module._load (internal/modules/cjs/loader.js:508:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at pw (/Users/suraj/Desktop/fake-news/tf.min.js:17:225676)
    at t.e.fetch (/Users/suraj/Desktop/fake-news/tf.min.js:17:225911)
    at t.<anonymous> (/Users/suraj/Desktop/fake-news/tf.min.js:17:255546)
    at u (/Users/suraj/Desktop/fake-news/tf.min.js:17:104674)
    at Generator._invoke (/Users/suraj/Desktop/fake-news/tf.min.js:17:104427)
    at Generator.forEach.t.(anonymous function) [as next] (/Users/suraj/Desktop/fake-news/tf.min.js:17:105031)
(node:35092) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
(node:35092) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

【问题讨论】:

    标签: javascript tensorflow machine-learning deep-learning tensorflow.js


    【解决方案1】:

    模块未正确导入。您很可能正在导入旨在在浏览器中运行的缩小脚本。 docs 介绍了如何开始使用 tensorflow.js

    安装包:

    npm install @tensorflow/tfjs
    

    用法

    import * as tf from '@tensorflow/tfjs';
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-16
      • 2021-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-19
      相关资源
      最近更新 更多