4

在使用 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

4

1 回答 1

1

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

async function predict(){
  const model = await tf.loadLayersModel('js/model.json');
  // do prediction
}
于 2020-05-23T21:45:36.140 回答