4

While executing the following code embedded in html using WAMP stack

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

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

During every run of the code, the ERR_EMPTY_RESPONSE is shown on different files.

The tfjs loaded using

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


PS:

While executing the code IDM starts downloading all the group1-shard__of22.bin files

I The model being loaded was created in python and is a tf.keras model. which has been converted using tfjs converter


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 :

> 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

Avi
  • 41
  • 1
  • 5

1 Answers1

1

Since Tensorflow works best in an asynchronous way, you should use an async function with await when loading the model:

async function predict(){
  const model = await tf.loadLayersModel('js/model.json');
  // do prediction
}
Martijn
  • 109
  • 1
  • 2
  • 8
  • I encountered the following error while using the above code : `errors.ts:48 Uncaught (in promise) Error: Provided weight data has no target variable: lstm_3/lstm_cell_3/kernel` – Avi May 24 '20 at 06:20
  • Please, your first question was ok, but keep your post to one question. And do some research before you ask, I found the solution by just googling your error. Here you can find the answer: https://stackoverflow.com/questions/55295671/uncaught-in-promise-error-provided-weight-data-has-no-target-variable-block1 – Martijn May 24 '20 at 09:12
  • I had already googled it, and found this one too, but it didn't work for me. – Avi May 24 '20 at 09:20
  • 1
    I have the following error: ```Error: Cannot proceed with model loading because the IOHandler provided does not have the `load` method implemented.``` – Loren Sep 02 '20 at 12:02
  • I think this has to do with something else. Please ask it in a new question with the provided code. – Martijn Sep 03 '20 at 19:04