Help appreciated.
Course 4 Week 4 Assignment 1
Coursera Environment: Python 3.7.0 TF 2.3.0 Numpy 1.18.4 Scipy 1.4.1. Programs run.
My Anaconda Environment: Python 3.9.12 TF 2.9.1 Numpy 1.23.5 Scipy 1.7.3.
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’)
Error:
ValueError Traceback (most recent call last)
Input In [3], in <cell line: 6>()
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’)
File ~\anaconda3\lib\site-packages\keras\saving\model_config.py:102, in model_from_json(json_string, custom_objects)
82 “”“Parses a JSON model configuration string and returns a model instance.
83
84 Usage:
(…)
99 A Keras model instance (uncompiled).
100 “””
101 from keras.layers import deserialize_from_json # pylint: disable=g-import-not-at-top
→ 102 return deserialize_from_json(json_string, custom_objects=custom_objects)
File ~\anaconda3\lib\site-packages\keras\layers\serialization.py:226, in deserialize_from_json(json_string, custom_objects)
221 populate_deserializable_objects()
222 config = json_utils.decode_and_deserialize(
223 json_string,
224 module_objects=LOCAL.ALL_OBJECTS,
225 custom_objects=custom_objects)
→ 226 return deserialize(config, custom_objects)
File ~\anaconda3\lib\site-packages\keras\layers\serialization.py:205, in deserialize(config, custom_objects)
168 “”“Instantiates a layer from a config dictionary.
169
170 Args:
(…)
202 ```
203 “””
204 populate_deserializable_objects()
→ 205 return generic_utils.deserialize_keras_object(
206 config,
207 module_objects=LOCAL.ALL_OBJECTS,
208 custom_objects=custom_objects,
209 printable_module_name=‘layer’)
File ~\anaconda3\lib\site-packages\keras\utils\generic_utils.py:679, in deserialize_keras_object(identifier, module_objects, custom_objects, printable_module_name)
676 custom_objects = custom_objects or {}
678 if ‘custom_objects’ in arg_spec.args:
→ 679 deserialized_obj = cls.from_config(
680 cls_config,
681 custom_objects=dict(
682 list(_GLOBAL_CUSTOM_OBJECTS.items()) +
683 list(custom_objects.items())))
684 else:
685 with CustomObjectScope(custom_objects):
File ~\anaconda3\lib\site-packages\keras\engine\training.py:2720, in Model.from_config(cls, config, custom_objects)
2716 functional_model_keys = [
2717 ‘name’, ‘layers’, ‘input_layers’, ‘output_layers’
2718 ]
2719 if all(key in config for key in functional_model_keys):
→ 2720 inputs, outputs, layers = functional.reconstruct_from_config(
2721 config, custom_objects)
2722 model = cls(inputs=inputs, outputs=outputs, name=config.get(‘name’))
2723 functional.connect_ancillary_layers(model, layers)
File ~\anaconda3\lib\site-packages\keras\engine\functional.py:1300, in reconstruct_from_config(config, custom_objects, created_layers)
1298 # First, we create all layers and enqueue nodes to be processed
1299 for layer_data in config[‘layers’]:
→ 1300 process_layer(layer_data)
1301 # Then we process nodes in order of layer depth.
1302 # Nodes that cannot yet be processed (if the inbound node
1303 # does not yet exist) are re-enqueued, and the process
1304 # is repeated until all nodes are processed.
1305 while unprocessed_nodes:
File ~\anaconda3\lib\site-packages\keras\engine\functional.py:1282, in reconstruct_from_config..process_layer(layer_data)
1278 else:
1279 # Instantiate layer.
1280 from keras.layers import deserialize as deserialize_layer # pylint: disable=g-import-not-at-top
→ 1282 layer = deserialize_layer(layer_data, custom_objects=custom_objects)
1283 created_layers[layer_name] = layer
1285 node_count_by_layer[layer] = int(_should_skip_first_node(layer))
File ~\anaconda3\lib\site-packages\keras\layers\serialization.py:205, in deserialize(config, custom_objects)
168 “”“Instantiates a layer from a config dictionary.
169
170 Args:
(…)
202 ```
203 “””
204 populate_deserializable_objects()
→ 205 return generic_utils.deserialize_keras_object(
206 config,
207 module_objects=LOCAL.ALL_OBJECTS,
208 custom_objects=custom_objects,
209 printable_module_name=‘layer’)
File ~\anaconda3\lib\site-packages\keras\utils\generic_utils.py:679, in deserialize_keras_object(identifier, module_objects, custom_objects, printable_module_name)
676 custom_objects = custom_objects or {}
678 if ‘custom_objects’ in arg_spec.args:
→ 679 deserialized_obj = cls.from_config(
680 cls_config,
681 custom_objects=dict(
682 list(_GLOBAL_CUSTOM_OBJECTS.items()) +
683 list(custom_objects.items())))
684 else:
685 with CustomObjectScope(custom_objects):
File ~\anaconda3\lib\site-packages\keras\layers\core\lambda_layer.py:303, in Lambda.from_config(cls, config, custom_objects)
300 @classmethod
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’)
307 output_shape = cls._parse_function_from_config(config, custom_objects,
308 ‘output_shape’,
309 ‘output_shape_module’,
310 ‘output_shape_type’)
311 if ‘mask’ in config:
File ~\anaconda3\lib\site-packages\keras\layers\core\lambda_layer.py:358, in Lambda._parse_function_from_config(cls, config, custom_objects, func_attr_name, module_attr_name, func_type_attr_name)
352 function = generic_utils.deserialize_keras_object(
353 config[func_attr_name],
354 custom_objects=custom_objects,
355 printable_module_name=‘function in Lambda layer’)
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]
File ~\anaconda3\lib\site-packages\keras\utils\generic_utils.py:793, 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)