Unable to load the keras-facenet model from local jupyter

Hi,
I am facing some error while trying to load the pre-trained model on my local system via jupyter.
You have used it in course 4(Face recognition)

Can you please let me know which python/keras/tensorflow version you use on this assignment.

Below is the error message:


ValueError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_14756/3412463693.py in
5 json_file.close()
6
----> 7 model = model_from_json(loaded_json_model)
8 model.load_weights(‘model.h5’)

~\Anaconda3\envs\dnnenv2\lib\site-packages\keras\saving\model_config.py in model_from_json(json_string, custom_objects)
102 config = json_utils.decode(json_string)
103 from keras.layers import deserialize # pylint: disable=g-import-not-at-top
→ 104 return deserialize(config, custom_objects=custom_objects)

~\Anaconda3\envs\dnnenv2\lib\site-packages\keras\layers\serialization.py in deserialize(config, custom_objects)
206 “”"
207 populate_deserializable_objects()
→ 208 return generic_utils.deserialize_keras_object(
209 config,
210 module_objects=LOCAL.ALL_OBJECTS,

~\Anaconda3\envs\dnnenv2\lib\site-packages\keras\utils\generic_utils.py in deserialize_keras_object(identifier, module_objects, custom_objects, printable_module_name)
672
673 if ‘custom_objects’ in arg_spec.args:
→ 674 deserialized_obj = cls.from_config(
675 cls_config,
676 custom_objects=dict(

~\Anaconda3\envs\dnnenv2\lib\site-packages\keras\engine\functional.py in from_config(cls, config, custom_objects)
660 “”"
661 with generic_utils.SharedObjectLoadingScope():
→ 662 input_tensors, output_tensors, created_layers = reconstruct_from_config(
663 config, custom_objects)
664 model = cls(inputs=input_tensors, outputs=output_tensors,

~\Anaconda3\envs\dnnenv2\lib\site-packages\keras\engine\functional.py in reconstruct_from_config(config, custom_objects, created_layers)
1271 # First, we create all layers and enqueue nodes to be processed
1272 for layer_data in config[‘layers’]:
→ 1273 process_layer(layer_data)
1274 # Then we process nodes in order of layer depth.
1275 # Nodes that cannot yet be processed (if the inbound node

~\Anaconda3\envs\dnnenv2\lib\site-packages\keras\engine\functional.py in process_layer(layer_data)
1253 from keras.layers import deserialize as deserialize_layer # pylint: disable=g-import-not-at-top
1254
→ 1255 layer = deserialize_layer(layer_data, custom_objects=custom_objects)
1256 created_layers[layer_name] = layer
1257

~\Anaconda3\envs\dnnenv2\lib\site-packages\keras\layers\serialization.py in deserialize(config, custom_objects)
206 “”"
207 populate_deserializable_objects()
→ 208 return generic_utils.deserialize_keras_object(
209 config,
210 module_objects=LOCAL.ALL_OBJECTS,

~\Anaconda3\envs\dnnenv2\lib\site-packages\keras\utils\generic_utils.py in deserialize_keras_object(identifier, module_objects, custom_objects, printable_module_name)
672
673 if ‘custom_objects’ in arg_spec.args:
→ 674 deserialized_obj = cls.from_config(
675 cls_config,
676 custom_objects=dict(

~\Anaconda3\envs\dnnenv2\lib\site-packages\keras\layers\core.py in from_config(cls, config, custom_objects)
1003 def from_config(cls, config, custom_objects=None):
1004 config = config.copy()
→ 1005 function = cls._parse_function_from_config(
1006 config, custom_objects, ‘function’, ‘module’, ‘function_type’)
1007

~\Anaconda3\envs\dnnenv2\lib\site-packages\keras\layers\core.py in _parse_function_from_config(cls, config, custom_objects, func_attr_name, module_attr_name, func_type_attr_name)
1055 elif function_type == ‘lambda’:
1056 # Unsafe deserialization from bytecode
→ 1057 function = generic_utils.func_load(
1058 config[func_attr_name], globs=globs)
1059 elif function_type == ‘raw’:

~\Anaconda3\envs\dnnenv2\lib\site-packages\keras\utils\generic_utils.py in func_load(code, defaults, closure, globs)
787 except (UnicodeEncodeError, binascii.Error):
788 raw_code = code.encode(‘raw_unicode_escape’)
→ 789 code = marshal.loads(raw_code)
790 if globs is None:
791 globs = globals()

ValueError: bad marshal data (unknown type code)

please advise how to fix it

Hey @clonesangram,
Apologies for the delayed response. A quick way to find out the versions of the packages involved is to do print(<package>.__version__) for all the packages involved. Make sure the packages are imported prior to this. Since the Coursera labs keeps on getting updated, make sure to download the file again since it might have been modified in accordance with the current versions of the packages. I hope this helps.

Regards,
Elemento