'TypeError: ('Keyword argument not understood:', 'config')

I am training an eye detection model under Mask RCNN and when I try to load a model using

new_model = load_model('./model/mask_rcnn_model.h5',custom_objects={'BatchNorm':KL.BatchNormalization, 'tf':tf, 'ProposalLayer':KE.Layer, 'PyramidROIAlign':KE.Layer, 'DetectionLayer':KE.Layer})

I got an error as follows

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-f53b858dfa65> in <module>
      2 
      3 # new_model = tf.compat.v1.keras.experimental.load_from_saved_model('./model/mask_rcnn_model.h5',)
----> 4 new_model = load_model('./model/mask_rcnn_model.h5',custom_objects={'BatchNorm':KL.BatchNormalization, 'tf':tf, 'ProposalLayer':KE.Layer, 'PyramidROIAlign':KE.Layer, 'DetectionLayer':KE.Layer})

~\anaconda3\envs\mask_rcnn\lib\site-packages\tensorflow\python\keras\saving\save.py in load_model(filepath, custom_objects, compile, options)
    205           (isinstance(filepath, h5py.File) or h5py.is_hdf5(filepath))):
    206         return hdf5_format.load_model_from_hdf5(filepath, custom_objects,
--> 207                                                 compile)
    208 
    209       filepath = path_to_string(filepath)

~\anaconda3\envs\mask_rcnn\lib\site-packages\tensorflow\python\keras\saving\hdf5_format.py in load_model_from_hdf5(filepath, custom_objects, compile)
    182     model_config = json_utils.decode(model_config.decode('utf-8'))
    183     model = model_config_lib.model_from_config(model_config,
--> 184                                                custom_objects=custom_objects)
    185 
    186     # set weights

~\anaconda3\envs\mask_rcnn\lib\site-packages\tensorflow\python\keras\saving\model_config.py in model_from_config(config, custom_objects)
     62                     '`Sequential.from_config(config)`?')
     63   from tensorflow.python.keras.layers import deserialize  # pylint: disable=g-import-not-at-top
---> 64   return deserialize(config, custom_objects=custom_objects)
     65 
     66 

~\anaconda3\envs\mask_rcnn\lib\site-packages\tensorflow\python\keras\layers\serialization.py in deserialize(config, custom_objects)
    175       module_objects=LOCAL.ALL_OBJECTS,
    176       custom_objects=custom_objects,
--> 177       printable_module_name='layer')

~\anaconda3\envs\mask_rcnn\lib\site-packages\tensorflow\python\keras\utils\generic_utils.py in deserialize_keras_object(identifier, module_objects, custom_objects, printable_module_name)
    356             custom_objects=dict(
    357                 list(_GLOBAL_CUSTOM_OBJECTS.items()) +
--> 358                 list(custom_objects.items())))
    359       with CustomObjectScope(custom_objects):
    360         return cls.from_config(cls_config)

~\anaconda3\envs\mask_rcnn\lib\site-packages\tensorflow\python\keras\engine\functional.py in from_config(cls, config, custom_objects)
    667     """
    668     input_tensors, output_tensors, created_layers = reconstruct_from_config(
--> 669         config, custom_objects)
    670     model = cls(inputs=input_tensors, outputs=output_tensors,
    671                 name=config.get('name'))

~\anaconda3\envs\mask_rcnn\lib\site-packages\tensorflow\python\keras\engine\functional.py in reconstruct_from_config(config, custom_objects, created_layers)
   1273   # First, we create all layers and enqueue nodes to be processed
   1274   for layer_data in config['layers']:
-> 1275     process_layer(layer_data)
   1276   # Then we process nodes in order of layer depth.
   1277   # Nodes that cannot yet be processed (if the inbound node

~\anaconda3\envs\mask_rcnn\lib\site-packages\tensorflow\python\keras\engine\functional.py in process_layer(layer_data)
   1255       from tensorflow.python.keras.layers import deserialize as deserialize_layer  # pylint: disable=g-import-not-at-top
   1256 
-> 1257       layer = deserialize_layer(layer_data, custom_objects=custom_objects)
   1258       created_layers[layer_name] = layer
   1259 

~\anaconda3\envs\mask_rcnn\lib\site-packages\tensorflow\python\keras\layers\serialization.py in deserialize(config, custom_objects)
    175       module_objects=LOCAL.ALL_OBJECTS,
    176       custom_objects=custom_objects,
--> 177       printable_module_name='layer')

~\anaconda3\envs\mask_rcnn\lib\site-packages\tensorflow\python\keras\utils\generic_utils.py in deserialize_keras_object(identifier, module_objects, custom_objects, printable_module_name)
    358                 list(custom_objects.items())))
    359       with CustomObjectScope(custom_objects):
--> 360         return cls.from_config(cls_config)
    361     else:
    362       # Then `cls` may be a function returning a class.

~\anaconda3\envs\mask_rcnn\lib\site-packages\tensorflow\python\keras\engine\base_layer.py in from_config(cls, config)
    718         A layer instance.
    719     """
--> 720     return cls(**config)
    721 
    722   def compute_output_shape(self, input_shape):

~\anaconda3\envs\mask_rcnn\lib\site-packages\tensorflow\python\training\tracking\base.py in _method_wrapper(self, *args, **kwargs)
    515     self._self_setattr_tracking = False  # pylint: disable=protected-access
    516     try:
--> 517       result = method(self, *args, **kwargs)
    518     finally:
    519       self._self_setattr_tracking = previous_value  # pylint: disable=protected-access

~\anaconda3\envs\mask_rcnn\lib\site-packages\tensorflow\python\keras\engine\base_layer_v1.py in __init__(self, trainable, name, dtype, dynamic, **kwargs)
    163     }
    164     # Validate optional keyword arguments.
--> 165     generic_utils.validate_kwargs(kwargs, allowed_kwargs)
    166 
    167     # Mutable properties

~\anaconda3\envs\mask_rcnn\lib\site-packages\tensorflow\python\keras\utils\generic_utils.py in validate_kwargs(kwargs, allowed_kwargs, error_message)
    806   for kwarg in kwargs:
    807     if kwarg not in allowed_kwargs:
--> 808       raise TypeError(error_message, kwarg)
    809 
    810 

TypeError: ('Keyword argument not understood:', 'config')

I am currently working on Jupyter Notebook and using Tensorflow 2.4 and Keras 2.4.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source