tf.keras.models.load_model return ValueError: A merge layer should be called on a list of inputs

  keras, python, python-3.x, tensorflow

I’m new to Tensorflow and Python and I have been following this tutorial, specifically along Titanic section. However, the data I was using was data of XYZ position of 20 joints captured from Kinect.

I have saved my model with model.save but when I tried to load the model, I got the following error:

ValueError                                Traceback (most recent call last)
<ipython-input-116-5833da799dfe> in <module>()
      1 Gait_gender_model.save('gait_gender_model')
      2 
----> 3 reloaded = tf.keras.models.load_model('gait_gender_model')

11 frames
/usr/local/lib/python3.7/dist-packages/keras/saving/save.py in load_model(filepath, custom_objects, compile, options)
    203         filepath = path_to_string(filepath)
    204         if isinstance(filepath, str):
--> 205           return saved_model_load.load(filepath, compile, options)
    206 
    207   raise IOError(

/usr/local/lib/python3.7/dist-packages/keras/saving/saved_model/load.py in load(path, compile, options)
    141 
    142   # Finalize the loaded layers and remove the extra tracked dependencies.
--> 143   keras_loader.finalize_objects()
    144   keras_loader.del_tracking()
    145 

/usr/local/lib/python3.7/dist-packages/keras/saving/saved_model/load.py in finalize_objects(self)
    642 
    643     # Initialize graph networks, now that layer dependencies have been resolved.
--> 644     self._reconstruct_all_models()
    645 
    646   def _unblock_model_reconstruction(self, layer_id, layer):

/usr/local/lib/python3.7/dist-packages/keras/saving/saved_model/load.py in _reconstruct_all_models(self)
    661       all_initialized_models.add(model_id)
    662       model, layers = self.model_layer_dependencies[model_id]
--> 663       self._reconstruct_model(model_id, model, layers)
    664       _finalize_config_layers([model])
    665 

/usr/local/lib/python3.7/dist-packages/keras/saving/saved_model/load.py in _reconstruct_model(self, model_id, model, layers)
    707       (inputs, outputs,
    708        created_layers) = functional_lib.reconstruct_from_config(
--> 709            config, created_layers={layer.name: layer for layer in layers})
    710       model.__init__(inputs, outputs, name=config['name'])
    711       functional_lib.connect_ancillary_layers(model, created_layers)

/usr/local/lib/python3.7/dist-packages/keras/engine/functional.py in reconstruct_from_config(config, custom_objects, created_layers)
   1281       if layer in unprocessed_nodes:
   1282         for node_data in unprocessed_nodes.pop(layer):
-> 1283           process_node(layer, node_data)
   1284 
   1285   input_tensors = []

/usr/local/lib/python3.7/dist-packages/keras/engine/functional.py in process_node(layer, node_data)
   1229         input_tensors = (
   1230             base_layer_utils.unnest_if_single_tensor(input_tensors))
-> 1231       output_tensors = layer(input_tensors, **kwargs)
   1232 
   1233       # Update node index map.

/usr/local/lib/python3.7/dist-packages/keras/engine/base_layer.py in __call__(self, *args, **kwargs)
    975     if _in_functional_construction_mode(self, inputs, args, kwargs, input_list):
    976       return self._functional_construction_call(inputs, args, kwargs,
--> 977                                                 input_list)
    978 
    979     # Maintains info about the `Layer.call` stack.

/usr/local/lib/python3.7/dist-packages/keras/engine/base_layer.py in _functional_construction_call(self, inputs, args, kwargs, input_list)
   1113       # Check input assumptions set after layer building, e.g. input shape.
   1114       outputs = self._keras_tensor_symbolic_call(
-> 1115           inputs, input_masks, args, kwargs)
   1116 
   1117       if outputs is None:

/usr/local/lib/python3.7/dist-packages/keras/engine/base_layer.py in _keras_tensor_symbolic_call(self, inputs, input_masks, args, kwargs)
    846       return tf.nest.map_structure(keras_tensor.KerasTensor, output_signature)
    847     else:
--> 848       return self._infer_output_signature(inputs, args, kwargs, input_masks)
    849 
    850   def _infer_output_signature(self, inputs, args, kwargs, input_masks):

/usr/local/lib/python3.7/dist-packages/keras/engine/base_layer.py in _infer_output_signature(self, inputs, args, kwargs, input_masks)
    886           self._maybe_build(inputs)
    887           inputs = self._maybe_cast_inputs(inputs)
--> 888           outputs = call_fn(inputs, *args, **kwargs)
    889 
    890         self._handle_activity_regularization(inputs, outputs)

/usr/local/lib/python3.7/dist-packages/keras/layers/merge.py in call(self, inputs)
    115   def call(self, inputs):
    116     if not isinstance(inputs, (list, tuple)):
--> 117       raise ValueError('A merge layer should be called on a list of inputs.')
    118     if self._reshape_required:
    119       reshaped_inputs = []

ValueError: A merge layer should be called on a list of inputs.

I have tried searching for a solution for a whole day but was unable to find anything. Please advise.

Thank you.

Source: Python-3x Questions

LEAVE A COMMENT