【问题标题】:Tensorflow JS tfjs | Unable to load model using tf.loadLayersModelTensorFlow JS tfjs |无法使用 tf.loadLayersModel 加载模型
【发布时间】:2020-05-22 21:52:14
【问题描述】:

在使用 WAMP 堆栈执行以下嵌入在 html 中的代码时

const model = tf.loadLayersModel('js/model.json');

我在chrome中遇到以下错误

> Uncaught (in promise) TypeError: Failed to fetch

> platform_browser.ts:28 GET http://localhost/poemgenerator/js/group1-shard3of22.bin net::ERR_EMPTY_RESPONSE

> Uncaught (in promise) TypeError: Failed to fetch

我在提到的位置有所有 group1-shard__of22.bin

在每次运行代码期间,ERR_EMPTY_RESPONSE 会显示在不同的文件中。

使用加载的 tfjs

<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@1.7.2/dist/tf.min.js"></script>


PS:

在执行代码时,IDM 开始下载所有 group1-shard__of22.bin 文件

I 正在加载的模型是在 python 中创建的,并且是一个 tf.keras 模型。已使用 tfjs 转换器进行转换


更新:

我用

替换了上面的代码
async function predict(){
  const model = await tf.loadLayersModel('js/model.json');
  model.summary()
}

并且还删除了 IDM,但它显示了另一个错误:

> errors.ts:48 Uncaught (in promise) Error: Provided weight data has no target variable: lstm_3/lstm_cell_3/kernel

> (index):68 Uncaught TypeError: model.summary is not a function

【问题讨论】:

    标签: javascript tensorflow tf.keras tensorflow.js tfjs-node


    【解决方案1】:

    由于 Tensorflow 以异步方式工作得最好,因此在加载模型时应该使用带有 await 的 async 函数:

    async function predict(){
      const model = await tf.loadLayersModel('js/model.json');
      // do prediction
    }
    

    【讨论】:

    • 我在使用上述代码时遇到以下错误:errors.ts:48 Uncaught (in promise) Error: Provided weight data has no target variable: lstm_3/lstm_cell_3/kernel
    • 拜托,您的第一个问题没问题,但请保持您的帖子只回答一个问题。在你问之前做一些研究,我只是通过谷歌搜索你的错误找到了解决方案。在这里你可以找到答案:stackoverflow.com/questions/55295671/…
    • 我已经用谷歌搜索过了,也找到了这个,但它对我不起作用。
    • 我有以下错误:Error: Cannot proceed with model loading because the IOHandler provided does not have the `load` method implemented.
    • 我认为这与其他事情有关。请使用提供的代码在新问题中提问。
    猜你喜欢
    • 1970-01-01
    • 2020-10-13
    • 2020-03-13
    • 1970-01-01
    • 2022-08-10
    • 2021-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多