question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unknown initializer: GlorotUniform when loading Keras model

See original GitHub issue

TensorFlow.js version

Version 0.13.2

Browser version

Google Chrome Version 69.0.3497.100 (64-bit)

Describe the problem or feature request

I am currently trying to load a convolutional neural network model from Keras (version 2.2.4) that has been converted using the tensorflow_converter utility (pip tensorflowjs version 0.6.4).

Upon loading the model, I am met with the following error:

Uncaught (in promise) Error: Unknown initializer: GlorotUniform. This may be due to one of the following reasons:
1. The initializer is defined in Python, in which case it needs to be ported to TensorFlow.js or your JavaScript code.
2. The custom initializer is defined in JavaScript, but is not registered properly with tf.serialization.registerClass().
    at new t (tfjs@0.13.2:2)
    at deserializeKerasObject (tfjs@0.13.2:2)
    at deserializeInitializer (tfjs@0.13.2:2)
    at getInitializer (tfjs@0.13.2:2)
    at t [as constructor] (tfjs@0.13.2:2)
    at new t (tfjs@0.13.2:2)
    at e.fromConfig (tfjs@0.13.2:2)
    at deserializeKerasObject (tfjs@0.13.2:2)
    at deserialize (tfjs@0.13.2:2)
    at i (tfjs@0.13.2:2)

However, the GlorotUniform initializer is part of tensorflowjs (https://js.tensorflow.org/api/0.13.0/#initializers.glorotUniform).

I have attached the model.json file that I’d like to load to this issue: model.zip

Code to reproduce the bug / link to feature request

const model = tf.loadModel("./model.json");

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8

github_iconTop GitHub Comments

26reactions
Soufiane-Fartitcommented, Dec 8, 2018

capture du 2018-12-08 01-37-34

I had the problem using this command: loaded_model = model_from_json(loaded_model_json)

but when I add (tf.keras.models.): loaded_model = tf.keras.models.model_from_json(loaded_model_json)

it works just fine

11reactions
AbdurRafaecommented, Jan 8, 2019

@Soufiane-Fartit I am still getting this error in tensorflow-js. Do you how to solve this?

Try adding the following in the model load function call.

custom_objects={“GlorotUniform”: tf.keras.initializers.glorot_uniform}

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unknown initializer: GlorotUniform when loading Keras model
I ran into the same issue. After changing: from tensorflow import keras. to: import keras. life is once again worth living.
Read more >
Unknown initializer: GlorotUniform when loading Keras model
I trained my CNN (VGG) through google colab and generated .h5 file. Now problem is, I can predict my output successfully through google ......
Read more >
Unknown initializer: GlorotUniform when loading Keras model
It seems like a serialization bug in keras. If you wrap your load_model with the below CustomObjectScope method, it would work fine. For...
Read more >
GlorotUniform when using models.model_from_json(json)
[Solved] ValueError: Unknown initializer: GlorotUniform when ... Hi there, if you are trying to load tensorflow neural network model from ...
Read more >
tf.keras.initializers.GlorotUniform | TensorFlow v2.11.0
The Glorot uniform initializer, also called Xavier uniform initializer. ... covering diffusion models with KerasCV, on-device ML, and more.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found