问题描述
使用Google Colab训练模型后,我使用以下命令(在Google Colab内部)下载了该模型:
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')
我的问题是,当我尝试使用本地计算机(Google Colab外部)加载下载的 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:
[输入]
from keras.models import load_model
model = load_model(model.h5)
[输出]
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')
有人知道不理解这个'groups'关键字参数是什么吗?我没有使用from keras.models
,而是尝试使用from tensorflow.keras.models
,但是没有成功,但是出现了相同的错误.在Google Colab和本地计算机上,我都在运行Keras'2.4.3'
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'
谢谢大家!
推荐答案
我之前评论说,做同样的事情我有同样的错误.我只是通过在本地计算机pip install --upgrade tensorflow
和pip install --upgrade keras
上同时升级tensorflow和keras来解决它.
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
and pip install --upgrade keras
.
该错误可能是由于Colab与本地计算机之间的软件包版本不同所致.希望这也对您有用.
The error was probably due to differing versions of the packages between Colab and local machine. Hope this works for you, too.
这篇关于keras.models load_model中的TypeError('关键字自变量不被理解:','groups')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!