TypeError :(“关键字参数无法理解:”,“组”)

时间:2020-08-20 07:01:36

标签: tensorflow keras cnn

在TensorFlow-Keras中训练CNN模型后,在打开具有以下功能的模型文件时,标题中出现了此错误:

from tensorflow.keras import load_model
# I also tried:
# from tensorflow.compat.v1.keras.models import load_model

model = load_model('weights-improvement-70-0.57.hdf5', compile = False)

weights-improvement-70-0.57.hdf5是我的模型文件。以下是我从终端引用的错误的详细形式:

Traceback (most recent call last):
  File "testing_with_landmark.py", line 59, in <module>
    PREDICTOR = load_model('weights-improvement-70-0.57.hdf5', compile = True)
  File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/keras/saving/save.py", line 143, in load_model
    return hdf5_format.load_model_from_hdf5(filepath, custom_objects, compile)
  File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/keras/saving/hdf5_format.py", line 162, in load_model_from_hdf5
    custom_objects=custom_objects)
  File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/keras/saving/model_config.py", line 55, in model_from_config
    return deserialize(config, custom_objects=custom_objects)
  File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/keras/layers/serialization.py", line 105, in deserialize
    printable_module_name='layer')
  File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/keras/utils/generic_utils.py", line 191, in deserialize_keras_object
    list(custom_objects.items())))
  File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/sequential.py", line 368, in from_config
    custom_objects=custom_objects)
  File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/keras/layers/serialization.py", line 105, in deserialize
    printable_module_name='layer')
  File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/keras/utils/generic_utils.py", line 193, in deserialize_keras_object
    return cls.from_config(cls_config)
  File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/base_layer.py", line 601, in from_config
    return cls(**config)
  File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/keras/layers/convolutional.py", line 498, in __init__
    **kwargs)
  File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/keras/layers/convolutional.py", line 122, in __init__
    **kwargs)
  File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/training/tracking/base.py", line 457, in _method_wrapper
    result = method(self, *args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/base_layer.py", line 300, in __init__
    generic_utils.validate_kwargs(kwargs, allowed_kwargs)
  File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/keras/utils/generic_utils.py", line 599, in validate_kwargs
    raise TypeError(error_message, kwarg)
TypeError: ('Keyword argument not understood:', 'groups')

为什么会这样?

1 个答案:

答案 0 :(得分:1)

问题是因为您要加载模型权重作为模型。

要加载模型,您应该首先创建模型或从已保存的模型(json文件或模型检查点)加载,然后使用:load_weights(<model_weight_path>)