load_model in tf>=2.3.0 raises TypeError when loading a model saved in tf 2.2.0 #45288

wonderful world·2021년 9월 6일
0

https://github.com/tensorflow/tensorflow/issues/45288

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-1-8326baccad65> in <module>()
      1 # Restart the runtime, then run
      2 import tensorflow as tf
----> 3 model = tf.keras.models.load_model('hidden_net')

9 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/functional.py in reconstruct_from_config(config, custom_objects, created_layers)
   1234     layer = created_layers[layer_name]
   1235     node_index = get_node_index(layer, node_index)
-> 1236     layer_output_tensors = layer._inbound_nodes[node_index].output_tensors
   1237     output_tensors.append(nest.flatten(layer_output_tensors)[tensor_index])
   1238 

TypeError: list indices must be integers or slices, not NoneType

Due to missing input shape at the front of Sequential layer.
So we need to fix the model by explcitly specifying input_shape.

But there seems to a workaround like the below.

tf.compat.v1.disable_eager_execution()

It allows to load the model which occurs in TypeError.

profile
hello wirld

0개의 댓글