Hi,
I can run the code perfectly in coursera jupyter notebook, but while running into my computer, I have faced this problem.
For the following code:
from tensorflow.keras.models import model_from_json
json_file = open('keras-facenet-h5/model.json', 'r')
loaded_model_json = json_file.read()
json_file.close()
model = model_from_json(loaded_model_json)
model.load_weights('keras-facenet-h5/model.h5')
I am getting this error:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
C:\Users\NAFISA~1.SAM\AppData\Local\Temp/ipykernel_7476/324912946.py in <module>
4 loaded_model_json = json_file.read()
5 json_file.close()
----> 6 model = model_from_json(loaded_model_json)
7 model.load_weights('keras-facenet-h5/model.h5')
~\anaconda3\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\lib\site-packages\keras\layers\serialization.py in deserialize(config, custom_objects)
205 """
206 populate_deserializable_objects()
--> 207 return generic_utils.deserialize_keras_object(
208 config,
209 module_objects=LOCAL.ALL_OBJECTS,
~\anaconda3\lib\site-packages\keras\utils\generic_utils.py in deserialize_keras_object(identifier, module_objects, custom_objects, printable_module_name)
677
678 if 'custom_objects' in arg_spec.args:
--> 679 deserialized_obj = cls.from_config(
680 cls_config,
681 custom_objects=dict(
~\anaconda3\lib\site-packages\keras\engine\functional.py in from_config(cls, config, custom_objects)
706 if all(key in config for key in [
707 'name', 'layers', 'input_layers', 'output_layers']):
--> 708 input_tensors, output_tensors, created_layers = reconstruct_from_config(
709 config, custom_objects)
710 model = cls(
~\anaconda3\lib\site-packages\keras\engine\functional.py in reconstruct_from_config(config, custom_objects, created_layers)
1324 # First, we create all layers and enqueue nodes to be processed
1325 for layer_data in config['layers']:
-> 1326 process_layer(layer_data)
1327 # Then we process nodes in order of layer depth.
1328 # Nodes that cannot yet be processed (if the inbound node
~\anaconda3\lib\site-packages\keras\engine\functional.py in process_layer(layer_data)
1306 from keras.layers import deserialize as deserialize_layer # pylint: disable=g-import-not-at-top
1307
-> 1308 layer = deserialize_layer(layer_data, custom_objects=custom_objects)
1309 created_layers[layer_name] = layer
1310
~\anaconda3\lib\site-packages\keras\layers\serialization.py in deserialize(config, custom_objects)
205 """
206 populate_deserializable_objects()
--> 207 return generic_utils.deserialize_keras_object(
208 config,
209 module_objects=LOCAL.ALL_OBJECTS,
~\anaconda3\lib\site-packages\keras\utils\generic_utils.py in deserialize_keras_object(identifier, module_objects, custom_objects, printable_module_name)
677
678 if 'custom_objects' in arg_spec.args:
--> 679 deserialized_obj = cls.from_config(
680 cls_config,
681 custom_objects=dict(
~\anaconda3\lib\site-packages\keras\layers\core\lambda_layer.py in from_config(cls, config, custom_objects)
301 def from_config(cls, config, custom_objects=None):
302 config = config.copy()
--> 303 function = cls._parse_function_from_config(config, custom_objects,
304 'function', 'module',
305 'function_type')
~\anaconda3\lib\site-packages\keras\layers\core\lambda_layer.py in _parse_function_from_config(cls, config, custom_objects, func_attr_name, module_attr_name, func_type_attr_name)
356 elif function_type == 'lambda':
357 # Unsafe deserialization from bytecode
--> 358 function = generic_utils.func_load(config[func_attr_name], globs=globs)
359 elif function_type == 'raw':
360 function = config[func_attr_name]
~\anaconda3\lib\site-packages\keras\utils\generic_utils.py in func_load(code, defaults, closure, globs)
791 except (UnicodeEncodeError, binascii.Error):
792 raw_code = code.encode('raw_unicode_escape')
--> 793 code = marshal.loads(raw_code)
794 if globs is None:
795 globs = globals()
ValueError: bad marshal data (unknown type code)
How can I solve this?