简体   繁体   English

Tensorflow JS tfjs | 无法使用 tf.loadLayersModel 加载 model

[英]Tensorflow JS tfjs | Unable to load model using tf.loadLayersModel

While executing the following code embedded in html using WAMP stack在使用 WAMP 堆栈执行 html 中嵌入的以下代码时

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

I encounter the following errors in chrome我在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

I have all the group1-shard__of22.bin present at the mentioned location我在提到的位置有所有 group1-shard__of22.bin

During every run of the code, the ERR_EMPTY_RESPONSE is shown on different files.在每次运行代码期间,ERR_EMPTY_RESPONSE 都会显示在不同的文件中。

The tfjs loaded using使用加载的 tfjs

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


PS: PS:

While executing the code IDM starts downloading all the group1-shard__of22.bin files在执行代码时,IDM 开始下载所有 group1-shard__of22.bin 文件

I The model being loaded was created in python and is a tf.keras model.我正在加载的 model 是在 python 中创建的,是一个 tf.keras Z20F35E630DAF439DBFA4C3F68CF58 which has been converted using tfjs converter已使用 tfjs 转换器转换


Update:更新:

I used the replaced the above code with我用替换了上面的代码

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

And also removed IDM but it showed another errors:并且还删除了 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

Since Tensorflow works best in an asynchronous way, you should use an async function with await when loading the model:由于 Tensorflow 以异步方式工作得最好,您应该在加载 model 时使用带有等待的异步 function:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM