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

Error in loading weights

Open 1224wxwx opened this issue 5 years ago • 3 comments

Hi, I downloaded your pre-trained weights and tried to load it, but I got error like:

"ValueError: You are trying to load a weight file containing 31 layers into a model with 111 layers."

model = ShuffleNetV2(include_top=True)
model.load_weights('shufflenetv2_emotion_recogn.h5')

Could you please tell me how to resolve it?

1224wxwx avatar May 07 '19 12:05 1224wxwx

try to use: model = load_model(model_path)

opconty avatar May 08 '19 00:05 opconty

try to use: model = load_model(model_path)

Thank you for replaying!

I tried "load_model" but got another error:

_/opt/conda/lib/python2.7/site-packages/keras/engine/saving.pyc in load_model(filepath, custom_objects, compile) 417 f = h5dict(filepath, 'r') 418 try: --> 419 model = _deserialize_model(f, custom_objects, compile) 420 finally: 421 if opened_new_file:

/opt/conda/lib/python2.7/site-packages/keras/engine/saving.pyc in _deserialize_model(f, custom_objects, compile) 223 raise ValueError('No model found in config.') 224 model_config = json.loads(model_config.decode('utf-8')) --> 225 model = model_from_config(model_config, custom_objects=custom_objects) 226 model_weights_group = f['model_weights'] 227

/opt/conda/lib/python2.7/site-packages/keras/engine/saving.pyc in model_from_config(config, custom_objects) 456 'Sequential.from_config(config)?') 457 from ..layers import deserialize --> 458 return deserialize(config, custom_objects=custom_objects) 459 460

/opt/conda/lib/python2.7/site-packages/keras/layers/init.pyc in deserialize(config, custom_objects) 53 module_objects=globs, 54 custom_objects=custom_objects, ---> 55 printable_module_name='layer')

/opt/conda/lib/python2.7/site-packages/keras/utils/generic_utils.pyc in deserialize_keras_object(identifier, module_objects, custom_objects, printable_module_name) 143 config['config'], 144 custom_objects=dict(list(_GLOBAL_CUSTOM_OBJECTS.items()) + --> 145 list(custom_objects.items()))) 146 with CustomObjectScope(custom_objects): 147 return cls.from_config(config['config'])

/opt/conda/lib/python2.7/site-packages/keras/engine/network.pyc in from_config(cls, config, custom_objects) 1020 # First, we create all layers and enqueue nodes to be processed 1021 for layer_data in config['layers']: -> 1022 process_layer(layer_data) 1023 # Then we process nodes in order of layer depth. 1024 # Nodes that cannot yet be processed (if the inbound node

/opt/conda/lib/python2.7/site-packages/keras/engine/network.pyc in process_layer(layer_data) 1006 1007 layer = deserialize_layer(layer_data, -> 1008 custom_objects=custom_objects) 1009 created_layers[layer_name] = layer 1010

/opt/conda/lib/python2.7/site-packages/keras/layers/init.pyc in deserialize(config, custom_objects) 53 module_objects=globs, 54 custom_objects=custom_objects, ---> 55 printable_module_name='layer')

/opt/conda/lib/python2.7/site-packages/keras/utils/generic_utils.pyc in deserialize_keras_object(identifier, module_objects, custom_objects, printable_module_name) 143 config['config'], 144 custom_objects=dict(list(_GLOBAL_CUSTOM_OBJECTS.items()) + --> 145 list(custom_objects.items()))) 146 with CustomObjectScope(custom_objects): 147 return cls.from_config(config['config'])

/opt/conda/lib/python2.7/site-packages/keras/layers/core.pyc in from_config(cls, config, custom_objects) 733 elif function_type == 'lambda': 734 # Unsafe deserialization from bytecode --> 735 function = func_load(config['function'], globs=globs) 736 else: 737 raise TypeError('Unknown function type:', function_type)

/opt/conda/lib/python2.7/site-packages/keras/utils/generic_utils.pyc in func_load(code, defaults, closure, globs) 233 # backwards compatibility for models serialized prior to 2.1.2 234 raw_code = code.encode('raw_unicode_escape') --> 235 code = marshal.loads(raw_code) 236 if globs is None: 237 globs = globals()

ValueError: bad marshal data (unknown type code)_

Here's my code:

from keras.models import load_model
model = load_model('shufflenetv2_emotion_recogn.h5')

P.S. My keras version is '2.2.4' and my tensorflow version is '1.9.0'.

1224wxwx avatar May 08 '19 01:05 1224wxwx

My python version is, 3.6.8, maybe this is the curse

opconty avatar May 08 '19 04:05 opconty