Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not load the saved model #2

Open
athon2 opened this issue Sep 29, 2018 · 3 comments
Open

Can not load the saved model #2

athon2 opened this issue Sep 29, 2018 · 3 comments

Comments

@athon2
Copy link

athon2 commented Sep 29, 2018

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')
@Fuyaoyao
Copy link

Fuyaoyao commented Jul 6, 2019

I met the same issue...

1 similar comment
@Fuyaoyao
Copy link

Fuyaoyao commented Jul 6, 2019

I met the same issue...

@AAA-Fan
Copy link

AAA-Fan commented May 10, 2020

how 同do it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants