ValueError: Could not interpret initializer identifier: {'module': 'keras.initializers', 'class_name': 'Orthogonal', 'config': {'gain': 1.0, 'seed': None}, 'registered_name': None} 2024-04-08 17:26:21.702 503 GET /script-health-check (10.12.71.253) 420.29

I am encountering this error :
ValueError: Could not interpret initializer identifier: {‘module’: ‘keras.initializers’, ‘class_name’: ‘Orthogonal’, ‘config’: {‘gain’: 1.0, ‘seed’: None}, ‘registered_name’: None}
2024-04-08 17:26:21.702 503 GET /script-health-check (10.12.71.253) 420.29ms

The code works totally fine on localhost but does not work at streamlit webapp. I am unable to debug this. Any suggestion about this.

All codes can be found here : GitHub - sakshamdev123/stock-price-prediction-LSTM-model
Streamlit app : https://stock-price-prediction-lstm-model.streamlit.app/


[     UTC     ] Logs for stock-price-prediction-lstm-model.streamlit.app/
────────────────────────────────────────────────────────────────────────────────────────
  File "/home/adminuser/venv/lib/python3.9/site-packages/keras/src/layers/rnn/lstm.py", line 121, in __init__
    self.kernel_initializer = initializers.get(kernel_initializer)
  File "/home/adminuser/venv/lib/python3.9/site-packages/keras/src/initializers/__init__.py", line 117, in get
    raise ValueError(
ValueError: Could not interpret initializer identifier: {'module': 'keras.initializers', 'class_name': 'Orthogonal', 'config': {'gain': 1.0, 'seed': None}, 'registered_name': None}
2024-04-08 17:00:46.289 Uncaught app exception
Traceback (most recent call last):
  File "/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 584, in _run_script
    exec(code, module.__dict__)
  File "/mount/src/stock-price-prediction-lstm-model/app.py", line 146, in <module>
    main()
  File "/mount/src/stock-price-prediction-lstm-model/app.py", line 107, in main
    model, sc = load_model_and_scaler()
  File "/mount/src/stock-price-prediction-lstm-model/app.py", line 19, in load_model_and_scaler
    model = load_model(model_file)
  File "/home/adminuser/venv/lib/python3.9/site-packages/keras/src/saving/saving_api.py", line 183, in load_model
    return legacy_h5_format.load_model_from_hdf5(filepath)
  File "/home/adminuser/venv/lib/python3.9/site-packages/keras/src/legacy/saving/legacy_h5_format.py", line 133, in load_model_from_hdf5
    model = saving_utils.model_from_config(
  File "/home/adminuser/venv/lib/python3.9/site-packages/keras/src/legacy/saving/saving_utils.py", line 85, in model_from_config
    return serialization.deserialize_keras_object(
  File "/home/adminuser/venv/lib/python3.9/site-packages/keras/src/legacy/saving/serialization.py", line 495, in deserialize_keras_object
    deserialized_obj = cls.from_config(
  File "/home/adminuser/venv/lib/python3.9/site-packages/keras/src/models/sequential.py", line 326, in from_config
    layer = saving_utils.model_from_config(
  File "/home/adminuser/venv/lib/python3.9/site-packages/keras/src/legacy/saving/saving_utils.py", line 85, in model_from_config
    return serialization.deserialize_keras_object(
  File "/home/adminuser/venv/lib/python3.9/site-packages/keras/src/legacy/saving/serialization.py", line 504, in deserialize_keras_object
    deserialized_obj = cls.from_config(cls_config)
  File "/home/adminuser/venv/lib/python3.9/site-packages/keras/src/layers/rnn/lstm.py", line 646, in from_config
    return cls(**config)
  File "/home/adminuser/venv/lib/python3.9/site-packages/keras/src/layers/rnn/lstm.py", line 459, in __init__
    cell = LSTMCell(
  File "/home/adminuser/venv/lib/python3.9/site-packages/keras/src/layers/rnn/lstm.py", line 121, in __init__
    self.kernel_initializer = initializers.get(kernel_initializer)
  File "/home/adminuser/venv/lib/python3.9/site-packages/keras/src/initializers/__init__.py", line 117, in get
    raise ValueError(
ValueError: Could not interpret initializer identifier: {'module': 'keras.initializers', 'class_name': 'Orthogonal', 'config': {'gain': 1.0, 'seed': None}, 'registered_name': None}
2024-04-08 17:00:46.712 503 GET /script-health-check (10.12.71.253) 429.54ms

Hello @sakshamdev123 - a warm welcome to our Streamlit community! :balloon:

First, I just wanted to double-check whether the Keras and TensorFlow versions on your Streamlit hosting setup are the same as the ones you’ve got working locally?

Sometimes, if these versions don’t match, it can lead to serialization issues, especially with custom objects or initializers like Orthogonal.

Best,
Charly

Hey @Charly_Wargnier, thanks for answering this I realized I have old versions of packages on my system which works fine.
I didn’t specified packages version on requirements.txt due to which my app used latest version of the packages which created this issue.
After specifying the packages version on requirements.txt it works just fine.

Glad it solved your issue – Happy building! :hugs:

Charly

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.