5

I am new to machine learning and I was following this blog on how to write a model with mobilenet.

I managed to convert the .h5 file model and tried to implement it on my web app.

Unfortunately, when I try to load the JSON model I get this error:

Uncaught (in promise) Error: Provided weight data has no target variable: block1_conv1_2/kernel.

Screenshot of the error on a browser

I converted the .h5 model in the command line like so:

tensorflowjs_converter --input_format keras model.h5 ConvertedModel/

The code to load the model in the browser, I followed this blog

let model;
async function loadModel(name) {
  $(".progress-bar").show(); 
  model = undefined;
  model = await tf.loadModel(`ConvertedModel/model.json`);
    $(".progress-bar").hide();
}

To see the code of the model please refer to the blog link. But below is a screenshot of how the model is compiled. Model compilation

Dependencies:

  • Tensorflow 1.13.1
  • Python 3.6.0
  • tensorflowjs 1.0.1

Any help to fix this would be appreciated. Thank you so much.

Rstynbl
  • 545
  • 2
  • 6
  • 10

1 Answers1

7

It seems you've encountered this error where an extra suffix has been added to some of your weights.

You can work around this issue by manually removing these extra suffixes from your model.json:

block1_conv1_2/kernel 

should instead be:

block1_conv1/kernel

The 'Error in clip' bug has now been fixed so I'm not too sure why you've received this one, but once again you can work around this by manually editing the model.json, and changing every instance of:

{"type":"ndarray", "value":6}

to

6
BMcFadyen
  • 363
  • 3
  • 7
  • Hello! Thanks for your reply. Your suggestion took out the error message I had but returned this now Uncaught (in promise) Error: Error in clip: min (0) must be less than or equal to max ([object Object]). at assert (util.ts:81) at clipByValue_ (unary_ops.ts:335) at clipByValue (operation.ts:46) at t.call (advanced_activations.ts:59) at topology.ts:998 at nameScope (common.ts:52) at t.apply (topology.ts:957) at executeInternal (executor.ts:199) at executeInternal (executor.ts:194) at executeInternal (executor.ts:194) – Rstynbl Mar 23 '19 at 10:23
  • @Rstynbl I've updated my answer with the fix for this one too. Hope it helps! – BMcFadyen Mar 23 '19 at 10:58
  • I belive it should simply be: > "max_value": 6.0, – BMcFadyen Mar 23 '19 at 11:24
  • Thank you! Yes it works now! sorry for the last query, silly mistake! thanks for all your help! – Rstynbl Mar 23 '19 at 11:25
  • Happy to have helped! – BMcFadyen Mar 23 '19 at 11:26
  • I have a similar issue: errors.ts:48 Uncaught (in promise) Error: Provided weight data has no target variable: bidirectional/forward_lstm/lstm_cell_1/kernel , but editing the model.json to remove the extra suffixes does not solve the problem – Daniele Cordano Apr 06 '20 at 12:57