deeplabv3plus-keras icon indicating copy to clipboard operation
deeplabv3plus-keras copied to clipboard

Can not load the saved model

Open athon2 opened this issue 6 years ago • 3 comments

I'm trying to load the saved model . The model saves ok but when I try to load it with the code:

    custom_objects={"BilinearUpsampling":BilinearUpsampling}
    keras.models.load_model(model_file, custom_objects=custom_objects)

It throws an error TypeError: ('Keyword argument not understood:', 'size')

TypeError                                 Traceback (most recent call last)
<ipython-input-2-919f7be2ba45> in <module>()
----> 1 predict()

<ipython-input-1-657409a5c4ee> in predict(model_path, validation_file, labels, output_dir)
     23             output_dir=config["prediction_dir"]):
     24     tmp = BilinearUpsampling()
---> 25     model = load_old_model(model_path)
     26     validation_file_opened = tables.open_file(validation_file)
     27     n_samples = validation_file_opened.root.data.shape[0]

~/workspace/segmentation/2DSegNet/DeepLab/keras-deeplab-v3-plus/deeplabv3_plus_train.py in load_old_model(model_file)
    240         pass
    241     try:
--> 242         return load_model(model_file, custom_objects=custom_objects)
    243     except ValueError as error:
    244         if "InstanceNormalization" in str(error):

/usr/local/lib/python3.5/dist-packages/keras/models.py in load_model(filepath, custom_objects, compile)
    268             raise ValueError('No model found in config file.')
    269         model_config = json.loads(model_config.decode('utf-8'))
--> 270         model = model_from_config(model_config, custom_objects=custom_objects)
    271 
    272         # set weights

/usr/local/lib/python3.5/dist-packages/keras/models.py in model_from_config(config, custom_objects)
    345                         'Maybe you meant to use '
    346                         '`Sequential.from_config(config)`?')
--> 347     return layer_module.deserialize(config, custom_objects=custom_objects)
    348 
    349 

/usr/local/lib/python3.5/dist-packages/keras/layers/__init__.py in deserialize(config, custom_objects)
     53                                     module_objects=globs,
     54                                     custom_objects=custom_objects,
---> 55                                     printable_module_name='layer')

/usr/local/lib/python3.5/dist-packages/keras/utils/generic_utils.py in deserialize_keras_object(identifier, module_objects, custom_objects, printable_module_name)
    142                 return cls.from_config(config['config'],
    143                                        custom_objects=dict(list(_GLOBAL_CUSTOM_OBJECTS.items()) +
--> 144                                                            list(custom_objects.items())))
    145             with CustomObjectScope(custom_objects):
    146                 return cls.from_config(config['config'])

/usr/local/lib/python3.5/dist-packages/keras/engine/topology.py in from_config(cls, config, custom_objects)
   2523         # First, we create all layers and enqueue nodes to be processed
   2524         for layer_data in config['layers']:
-> 2525             process_layer(layer_data)
   2526         # Then we process nodes in order of layer depth.
   2527         # Nodes that cannot yet be processed (if the inbound node

/usr/local/lib/python3.5/dist-packages/keras/engine/topology.py in process_layer(layer_data)
   2509 
   2510             layer = deserialize_layer(layer_data,
-> 2511                                       custom_objects=custom_objects)
   2512             created_layers[layer_name] = layer
   2513 

/usr/local/lib/python3.5/dist-packages/keras/layers/__init__.py in deserialize(config, custom_objects)
     53                                     module_objects=globs,
     54                                     custom_objects=custom_objects,
---> 55                                     printable_module_name='layer')

/usr/local/lib/python3.5/dist-packages/keras/utils/generic_utils.py in deserialize_keras_object(identifier, module_objects, custom_objects, printable_module_name)
    144                                                            list(custom_objects.items())))
    145             with CustomObjectScope(custom_objects):
--> 146                 return cls.from_config(config['config'])
    147         else:
    148             # Then `cls` may be a function returning a class.

/usr/local/lib/python3.5/dist-packages/keras/engine/topology.py in from_config(cls, config)
   1269             A layer instance.
   1270         """
-> 1271         return cls(**config)
   1272 
   1273     def count_params(self):

~/workspace/segmentation/2DSegNet/DeepLab/keras-deeplab-v3-plus/deeplabv3_plus_model.py in __init__(self, upsampling, data_format, **kwargs)
     12         self.upsampling = conv_utils.normalize_tuple(upsampling, 2, 'size')
     13         self.input_spec = InputSpec(ndim=4)
---> 14         super(BilinearUpsampling, self).__init__(**kwargs)
     15 
     16     def compute_output_shape(self, input_shape):

/usr/local/lib/python3.5/dist-packages/keras/engine/topology.py in __init__(self, **kwargs)
    291         for kwarg in kwargs:
    292             if kwarg not in allowed_kwargs:
--> 293                 raise TypeError('Keyword argument not understood:', kwarg)
    294         name = kwargs.get('name')
    295         if not name:

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

athon2 avatar Sep 29 '18 14:09 athon2

I met the same issue...

Fuyaoyao avatar Jul 06 '19 10:07 Fuyaoyao

I met the same issue...

Fuyaoyao avatar Jul 06 '19 10:07 Fuyaoyao

how 同do it

AAA-Fan avatar May 10 '20 09:05 AAA-Fan