DonsetPG / narya

The Narya API allows you track soccer player from camera inputs, and evaluate them with an Expected Discounted Goal (EDG) Agent. This repository contains the implementation of the flowing paper https://arxiv.org/abs/2101.05388. We also make available all of our pretrained agents, and the datasets we used as well.
MIT License
166 stars 48 forks source link

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

Closed PareshKamble closed 3 years ago

PareshKamble commented 3 years ago

When I try to run _modelsexamples.ipynb in my local machine, I get the above said error. It usually happens in the line deep_homo_model = DeepHomoModel()

I installed all the requirements. What can be the possible source of error here?

Sorry for this long error.

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-6-3f60b79e4c6b> in <module>
      1 from narya.models.keras_models import DeepHomoModel
      2 
----> 3 deep_homo_model = DeepHomoModel()
      4 
      5 # WEIGHTS_PATH = (

~/Documents/narya/narya/models/keras_models.py in __init__(self, pretrained, input_shape)
     59         self.pretrained = pretrained
     60 
---> 61         self.resnet_18 = _build_resnet18()
     62 
     63         inputs = tf.keras.layers.Input((self.input_shape[0], self.input_shape[1], 3))

~/Documents/narya/narya/models/keras_models.py in _build_resnet18()
     34     )
     35 
---> 36     resnet18 = tf.keras.models.load_model(resnet18_path_to_file)
     37     resnet18.compile()
     38 

~/anaconda3/envs/narya/lib/python3.8/site-packages/tensorflow/python/keras/saving/save.py in load_model(filepath, custom_objects, compile)
    182     if (h5py is not None and (
    183         isinstance(filepath, h5py.File) or h5py.is_hdf5(filepath))):
--> 184       return hdf5_format.load_model_from_hdf5(filepath, custom_objects, compile)
    185 
    186     if sys.version_info >= (3, 4) and isinstance(filepath, pathlib.Path):

~/anaconda3/envs/narya/lib/python3.8/site-packages/tensorflow/python/keras/saving/hdf5_format.py in load_model_from_hdf5(filepath, custom_objects, compile)
    175       raise ValueError('No model found in config file.')
    176     model_config = json.loads(model_config.decode('utf-8'))
--> 177     model = model_config_lib.model_from_config(model_config,
    178                                                custom_objects=custom_objects)
    179 

~/anaconda3/envs/narya/lib/python3.8/site-packages/tensorflow/python/keras/saving/model_config.py in model_from_config(config, custom_objects)
     53                     '`Sequential.from_config(config)`?')
     54   from tensorflow.python.keras.layers import deserialize  # pylint: disable=g-import-not-at-top
---> 55   return deserialize(config, custom_objects=custom_objects)
     56 
     57 

~/anaconda3/envs/narya/lib/python3.8/site-packages/tensorflow/python/keras/layers/serialization.py in deserialize(config, custom_objects)
    103     config['class_name'] = _DESERIALIZATION_TABLE[layer_class_name]
    104 
--> 105   return deserialize_keras_object(
    106       config,
    107       module_objects=globs,

~/anaconda3/envs/narya/lib/python3.8/site-packages/tensorflow/python/keras/utils/generic_utils.py in deserialize_keras_object(identifier, module_objects, custom_objects, printable_module_name)
    367 
    368       if 'custom_objects' in arg_spec.args:
--> 369         return cls.from_config(
    370             cls_config,
    371             custom_objects=dict(

~/anaconda3/envs/narya/lib/python3.8/site-packages/tensorflow/python/keras/engine/network.py in from_config(cls, config, custom_objects)
    984         ValueError: In case of improperly formatted config dict.
    985     """
--> 986     input_tensors, output_tensors, created_layers = reconstruct_from_config(
    987         config, custom_objects)
    988     model = cls(inputs=input_tensors, outputs=output_tensors,

~/anaconda3/envs/narya/lib/python3.8/site-packages/tensorflow/python/keras/engine/network.py in reconstruct_from_config(config, custom_objects, created_layers)
   2017   # First, we create all layers and enqueue nodes to be processed
   2018   for layer_data in config['layers']:
-> 2019     process_layer(layer_data)
   2020   # Then we process nodes in order of layer depth.
   2021   # Nodes that cannot yet be processed (if the inbound node

~/anaconda3/envs/narya/lib/python3.8/site-packages/tensorflow/python/keras/engine/network.py in process_layer(layer_data)
   1999       from tensorflow.python.keras.layers import deserialize as deserialize_layer  # pylint: disable=g-import-not-at-top
   2000 
-> 2001       layer = deserialize_layer(layer_data, custom_objects=custom_objects)
   2002       created_layers[layer_name] = layer
   2003 

~/anaconda3/envs/narya/lib/python3.8/site-packages/tensorflow/python/keras/layers/serialization.py in deserialize(config, custom_objects)
    103     config['class_name'] = _DESERIALIZATION_TABLE[layer_class_name]
    104 
--> 105   return deserialize_keras_object(
    106       config,
    107       module_objects=globs,

~/anaconda3/envs/narya/lib/python3.8/site-packages/tensorflow/python/keras/utils/generic_utils.py in deserialize_keras_object(identifier, module_objects, custom_objects, printable_module_name)
    367 
    368       if 'custom_objects' in arg_spec.args:
--> 369         return cls.from_config(
    370             cls_config,
    371             custom_objects=dict(

~/anaconda3/envs/narya/lib/python3.8/site-packages/tensorflow/python/keras/layers/core.py in from_config(cls, config, custom_objects)
    988   def from_config(cls, config, custom_objects=None):
    989     config = config.copy()
--> 990     function = cls._parse_function_from_config(
    991         config, custom_objects, 'function', 'module', 'function_type')
    992 

~/anaconda3/envs/narya/lib/python3.8/site-packages/tensorflow/python/keras/layers/core.py in _parse_function_from_config(cls, config, custom_objects, func_attr_name, module_attr_name, func_type_attr_name)
   1040     elif function_type == 'lambda':
   1041       # Unsafe deserialization from bytecode
-> 1042       function = generic_utils.func_load(
   1043           config[func_attr_name], globs=globs)
   1044     elif function_type == 'raw':

~/anaconda3/envs/narya/lib/python3.8/site-packages/tensorflow/python/keras/utils/generic_utils.py in func_load(code, defaults, closure, globs)
    469   except (UnicodeEncodeError, binascii.Error):
    470     raw_code = code.encode('raw_unicode_escape')
--> 471   code = marshal.loads(raw_code)
    472   if globs is None:
    473     globs = globals()

ValueError: bad marshal data (unknown type code)
DonsetPG commented 3 years ago

Hey, what version of Python do you use? (I suspect it comes from a Python version below 3.7). Please try with Python >=3.8 and let me know if that solves your issue.

PareshKamble commented 3 years ago

Hi, I am using Python 3.8.9.

DonsetPG commented 3 years ago

My bad I told you the wrong version. Can you try with Python 3.7? This should solve the issue (we had the same problem during testing a few month ago)

PareshKamble commented 3 years ago

Sure. I shall give it a try asap. Thanks

PareshKamble commented 3 years ago

@DonsetPG it worked. Thanks.

mackenizm commented 1 year ago

Could you kindly provide some guidance as to how I could update the model to be compatible with Python 3.10?