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

ValueError: bad marshal data (unknown type code) #2

Open
dgolano opened this issue Nov 27, 2017 · 7 comments
Open

ValueError: bad marshal data (unknown type code) #2

dgolano opened this issue Nov 27, 2017 · 7 comments

Comments

@dgolano
Copy link

dgolano commented Nov 27, 2017

I'm just attempting to load the model below like you have in README.md,
but am getting the error: " ValueError: bad marshal data (unknown type code)".

These are the version of keras and python that I'm using.
Keras: 2.1.1
Python 3.6.2

Do I need to use a different version of Keras/Python?

from keras.models import load_model
from keras.utils import CustomObjectScope
import tensorflow as tf
with CustomObjectScope({'tf': tf}):
    model = load_model('Keras-OpenFace-master/model/nn4.small2.v1.h5')

ValueError Traceback (most recent call last)
in ()
3 import tensorflow as tf
4 with CustomObjectScope({'tf': tf}):
----> 5 model = load_model('Keras-OpenFace-master/model/nn4.small2.v1.h5')

//anaconda/envs/tf/lib/python3.6/site-packages/keras/models.py in load_model(filepath, custom_objects, compile)
238 raise ValueError('No model found in config file.')
239 model_config = json.loads(model_config.decode('utf-8'))
--> 240 model = model_from_config(model_config, custom_objects=custom_objects)
241
242 # set weights

//anaconda/envs/tf/lib/python3.6/site-packages/keras/models.py in model_from_config(config, custom_objects)
312 'Maybe you meant to use '
313 'Sequential.from_config(config)?')
--> 314 return layer_module.deserialize(config, custom_objects=custom_objects)
315
316

//anaconda/envs/tf/lib/python3.6/site-packages/keras/layers/init.py in deserialize(config, custom_objects)
53 module_objects=globs,
54 custom_objects=custom_objects,
---> 55 printable_module_name='layer')

//anaconda/envs/tf/lib/python3.6/site-packages/keras/utils/generic_utils.py in deserialize_keras_object(identifier, module_objects, custom_objects, printable_module_name)
137 return cls.from_config(config['config'],
138 custom_objects=dict(list(_GLOBAL_CUSTOM_OBJECTS.items()) +
--> 139 list(custom_objects.items())))
140 with CustomObjectScope(custom_objects):
141 return cls.from_config(config['config'])

//anaconda/envs/tf/lib/python3.6/site-packages/keras/engine/topology.py in from_config(cls, config, custom_objects)
2488 # First, we create all layers and enqueue nodes to be processed
2489 for layer_data in config['layers']:
-> 2490 process_layer(layer_data)
2491 # Then we process nodes in order of layer depth.
2492 # Nodes that cannot yet be processed (if the inbound node

//anaconda/envs/tf/lib/python3.6/site-packages/keras/engine/topology.py in process_layer(layer_data)
2474
2475 layer = deserialize_layer(layer_data,
-> 2476 custom_objects=custom_objects)
2477 created_layers[layer_name] = layer
2478

//anaconda/envs/tf/lib/python3.6/site-packages/keras/layers/init.py in deserialize(config, custom_objects)
53 module_objects=globs,
54 custom_objects=custom_objects,
---> 55 printable_module_name='layer')

//anaconda/envs/tf/lib/python3.6/site-packages/keras/utils/generic_utils.py in deserialize_keras_object(identifier, module_objects, custom_objects, printable_module_name)
137 return cls.from_config(config['config'],
138 custom_objects=dict(list(_GLOBAL_CUSTOM_OBJECTS.items()) +
--> 139 list(custom_objects.items())))
140 with CustomObjectScope(custom_objects):
141 return cls.from_config(config['config'])

//anaconda/envs/tf/lib/python3.6/site-packages/keras/layers/core.py in from_config(cls, config, custom_objects)
697 elif function_type == 'lambda':
698 # Unsafe deserialization from bytecode
--> 699 function = func_load(config['function'], globs=globs)
700 else:
701 raise TypeError('Unknown function type:', function_type)

//anaconda/envs/tf/lib/python3.6/site-packages/keras/utils/generic_utils.py in func_load(code, defaults, closure, globs)
198 if isinstance(defaults, list):
199 defaults = tuple(defaults)
--> 200 code = marshal.loads(code.encode('raw_unicode_escape'))
201 if globs is None:
202 globs = globals()

ValueError: bad marshal data (unknown type code)

@sagartesla
Copy link

@dgolano You should use python 2.7 .
I also got the same error related to bad marshal.
Now I am able to load these model without any error.
My current version are
python - 2.7.12
keras - 2.1.1
tensorflow- 1.0.0

@beimingmaster
Copy link

i have same error

@beimingmaster
Copy link

my environment:
python: 3.5.2
tensorflow: 1.3
cuda: 8.0

@cskostas87
Copy link

are you (@beimingmaster ) find a solution for bad marshal problem?

@tkwoo
Copy link

tkwoo commented Jul 17, 2018

my env:
python: 3.6
tf: 1.8
keras: 2.2

I also faced same problem. and sovled it.

  1. model.save('./model/nn4.small2.lrn.h5') using python 2.7
  2. load nn4.small2.lrn.h5 and save model.save_weights('weight.h5')
  3. create model structure file: https://gist.github.com/tkwoo/a9da631b3f7d437b8961a7d5276a6087
  4. model = facenet_keras.facenet()
  5. model.load_weights('weight.h5')

@Aditya-Ashtekar
Copy link

Aditya-Ashtekar commented May 17, 2020

!git clone https://github.com/TessFerrandez/research-papers.git
%cd research-papers/facenet
from model import create_model
%cd ../..
#check if '%pwd' prints '/content' if using google colab
#download facenet_keras.py and upload to your colab's 'content/' direcory #https://gist.github.com/tkwoo/a9da631b3f7d437b8961a7d5276a6087
import facenet_keras
model = facenet_keras.facenet()

@AlphaMoury
Copy link

Actually, now that tensoflow absorbed keras, we should make the respective modifications:

keras -> tensorflow.keras

and replace all things like keras.layers.* by keras.layers

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

7 participants