tensorflow / addons

Useful extra functionality for TensorFlow 2.x maintained by SIG-addons
Apache License 2.0
1.69k stars 611 forks source link

ValueError: Unknown layer: Addons>ESN #2787

Closed muriloasouza closed 1 year ago

muriloasouza commented 1 year ago

I have trained the following model:

model = Sequential(name='ESN_NE')
        model.add(InputLayer((timesteps, input_dim), name='Input_Layer'))
        model.add(ESN(units=200, activation=['tanh'], name='ESN'))
        # model.add(Flatten())
        model.add(Dense(units=100, activation=['tanh'], name='1_Dense'))
        model.add(Dense(units=48, activation=['tanh'], name='2_Dense'))
        model.add(Dense(units=24, activation=['tanh'], name='Output_Layer'))
        model.compile(optimizer='adam', loss='mean_squared_error')

And saved it in a .hdf5 file.

Now i am trying to load it to use my test set:

model = load_model('C:/.../ESN_model.hdf5')

But i am getting the following error:

Traceback (most recent call last):
  File "C:\Users\Muril\PycharmProjects\tf-gpu\venv\lib\site-packages\IPython\core\interactiveshell.py", line 3378, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-9-f2223f5f91dd>", line 1, in <module>
    model = load_model('C:/Users/Muril/PycharmProjects/tf-gpu/ESN/D+1/ESN_NE_D+1.hdf5')
  File "C:\Users\Muril\PycharmProjects\tf-gpu\venv\lib\site-packages\keras\utils\traceback_utils.py", line 67, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File "C:\Users\Muril\PycharmProjects\tf-gpu\venv\lib\site-packages\keras\utils\generic_utils.py", line 562, in class_and_config_for_serialized_keras_object
    raise ValueError(
ValueError: Unknown layer: Addons>ESN. Please ensure this object is passed to the `custom_objects` argument. See https://www.tensorflow.org/guide/keras/save_and_serialize#registering_the_custom_object for details.

How can i fix this?

bhack commented 1 year ago

Check https://keras.io/guides/serialization_and_saving/