tensorflow: Keras Model Errors on Loading - 'list' object has no attribute 'items'
System information
- Have I written custom code (as opposed to using a stock example script provided in TensorFlow): No
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10
- TensorFlow installed from (source or binary): pip
- TensorFlow version (use command below): 2.1.0
- Python version: 3.5.2
- CUDA/cuDNN version: CUDA 10.1 cuDNN 7.6
- GPU model and memory: Quadro M2000M 4.00GiB
Describe the current behavior
When trying to load one of my sequential models using tf.keras.models.load_model
an error is thrown at the following location:
tensorflow_core\python\keras\utils\generic_utils.py", line 254, in class_and_config_for_serialized_keras_object
for key, item in cls_config.items():
This code expects cls_config
to be a dictionary, while for this model it is a list of dictionaries.
I can successfully load and run this model using TensorFlow versions 2.0.0
, 1.14.0
and 1.4.0
(the version is was trained with)
This section of code was introduced when adding support for passive serialization in Keras
Describe the expected behavior
Can successfully load a model from a hdf5 file when its config is in the list format
Code to reproduce the issue
Execute the class_and_config_for_serialized_keras_object
function with a config of the following form:
{
"config": [
{
"config":
{
...
},
"class_name": "Conv2D"
},
...
],
"class_name": "Sequential"
}
Which is different from the form when I create a new model using TF v2.1.0 or 2.0.0 (I haven’t verified the form of the config with the other versions):
{
"config": {
"name": "sequential",
"layers": [
{
"config":
{
...
},
"class_name": "Conv2D"
},
...
]
},
"class_name": "Sequential"
}
Other info / logs
When loaded with tf.keras in v2.0.0 the layers, model config, inputs, outputs, summary etc. are all parsed correctly, as well as being able to run data through the model.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 19 (4 by maintainers)
Minimal reproducible code snippets
Using TensorFlow v1.4.0, Keras v2.1.1, CUDA v8.0.1 and cuDNN v6.0
Using TensorFlow v2.1.0, CUDA v10.1.105 and cuDNN v7.6
It looks like this will be fixed in TensorFlow 2.3: see #38135.
I had the same issue and I downgrade tensorflow to 2.0.0 and it works fine.