Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError('Keyword argument not understood:', 'groups') in keras.models load_model

After training a model using Google Colab, I downloaded it using the following command (inside Google Colab):

model.save('model.h5')
from google.colab import files
files.download('model.h5')

My problem is that when I try to load the downloaded model.h5 using my local machine (outside Google Colab), I get the following error:

[input]

from keras.models import load_model
model = load_model(model.h5)

[output]

Traceback (most recent call last):
  File "test.py", line 2, in <module>
    model = load_model(filepath = 'saved_model/model2.h5',custom_objects=None,compile=True, )
  File "/home/lucasmirachi/anaconda3/envs/myenviron/lib/python3.8/site-packages/tensorflow/python/keras/saving/save.py", line 184, in load_model
    return hdf5_format.load_model_from_hdf5(filepath, custom_objects, compile)
  File "/home/lucasmirachi/anaconda3/envs/myenviron/lib/python3.8/site-packages/tensorflow/python/keras/saving/hdf5_format.py", line 177, in load_model_from_hdf5
    model = model_config_lib.model_from_config(model_config,
  File "/home/lucasmirachi/anaconda3/envs/myenviron/lib/python3.8/site-packages/tensorflow/python/keras/saving/model_config.py", line 55, in model_from_config
    return deserialize(config, custom_objects=custom_objects)
  File "/home/lucasmirachi/anaconda3/envs/myenviron/lib/python3.8/site-packages/tensorflow/python/keras/layers/serialization.py", line 105, in deserialize
    return deserialize_keras_object(
  File "/home/lucasmirachi/anaconda3/envs/myenviron/lib/python3.8/site-packages/tensorflow/python/keras/utils/generic_utils.py", line 369, in deserialize_keras_object
    return cls.from_config(
  File "/home/lucasmirachi/anaconda3/envs/myenviron/lib/python3.8/site-packages/tensorflow/python/keras/engine/sequential.py", line 397, in from_config
    layer = layer_module.deserialize(layer_config,
  File "/home/lucasmirachi/anaconda3/envs/myenviron/lib/python3.8/site-packages/tensorflow/python/keras/layers/serialization.py", line 105, in deserialize
    return deserialize_keras_object(
  File "/home/lucasmirachi/anaconda3/envs/myenviron/lib/python3.8/site-packages/tensorflow/python/keras/utils/generic_utils.py", line 375, in deserialize_keras_object
    return cls.from_config(cls_config)
  File "/home/lucasmirachi/anaconda3/envs/myenviron/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py", line 655, in from_config
    return cls(**config)
  File "/home/lucasmirachi/anaconda3/envs/myenviron/lib/python3.8/site-packages/tensorflow/python/keras/layers/convolutional.py", line 582, in __init__
    super(Conv2D, self).__init__(
  File "/home/lucasmirachi/anaconda3/envs/myenviron/lib/python3.8/site-packages/tensorflow/python/keras/layers/convolutional.py", line 121, in __init__
    super(Conv, self).__init__(
  File "/home/lucasmirachi/anaconda3/envs/myenviron/lib/python3.8/site-packages/tensorflow/python/training/tracking/base.py", line 456, in _method_wrapper
    result = method(self, *args, **kwargs)
  File "/home/lucasmirachi/anaconda3/envs/myenviron/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py", line 294, in __init__
    generic_utils.validate_kwargs(kwargs, allowed_kwargs)
  File "/home/lucasmirachi/anaconda3/envs/myenviron/lib/python3.8/site-packages/tensorflow/python/keras/utils/generic_utils.py", line 792, in validate_kwargs
    raise TypeError(error_message, kwarg)
TypeError: ('Keyword argument not understood:', 'groups')

Does anyone know what is this 'groups' keyword argument not understood? Instead of using from keras.models I have tried using from tensorflow.keras.models but I had no success, I got the same error. In both Google Colab and on my local machine I'm running Keras '2.4.3'

Thank you all in advance!

like image 975
Lucas Mirachi Avatar asked Aug 07 '20 19:08

Lucas Mirachi


2 Answers

I commented earlier saying I had the same exact error from doing the same exact thing. I just solved it by upgrading both tensorflow and keras on my local machine

pip install --upgrade tensorflow
pip install --upgrade keras

The error was probably due to differing versions of the packages between Colab and local machine. Hope this works for you, too.

like image 62
Sam Skinner Avatar answered Nov 12 '22 00:11

Sam Skinner


I had the same issue because I was saving and loading the model with different versions of tensorflow. I saved a model with tf 2.3.0 then loaded it with tf 2.1.0.

I made sure that both saving and loading use the same venv which fixed the issue for me.

like image 4
jost Avatar answered Nov 12 '22 02:11

jost