2
votes

I'm creating a wide and deep model using Keras functional API on tensorflow.

When I try to merge the two models, the below error occurred.

--------------------------------------------------------------------------- ValueError Traceback (most recent call last) in () 1 merged_out = tf.keras.layers.concatenate([wide_model.output, deep_model.output]) 2 merged_out = tf.keras.layers.Dense(1)(merged_out) ----> 3 combined_model = tf.keras.Model(inputs=wide_model.input + [deep_model.input], outputs=merged_out) 4 print(combined_model.summary())

/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py in init(self, *args, **kwargs) 111 112 def init(self, *args, **kwargs): --> 113 super(Model, self).init(*args, **kwargs) 114 # Create a cache for iterator get_next op. 115 self._iterator_get_next = weakref.WeakKeyDictionary()

/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/network.py in init(self, *args, **kwargs) 77 'inputs' in kwargs and 'outputs' in kwargs): 78 # Graph network ---> 79 self._init_graph_network(*args, **kwargs) 80 else: 81 # Subclassed network

/usr/local/lib/python3.6/dist-packages/tensorflow/python/training/checkpointable/base.py in _method_wrapper(self, *args, **kwargs) 362 self._setattr_tracking = False # pylint: disable=protected-access 363 try: --> 364 method(self, *args, **kwargs) 365 finally: 366 self._setattr_tracking = previous_value # pylint: disable=protected-access

/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/network.py in _init_graph_network(self, inputs, outputs, name) 193 'must come from tf.layers.Input. ' 194 'Received: ' + str(x) + --> 195 ' (missing previous layer metadata).') 196 # Check that x is an input tensor. 197 # pylint: disable=protected-access

ValueError: Input tensors to a Model must come from tf.layers.Input. Received: Tensor("add_1:0", shape=(1, ?, 163), dtype=float32) (missing previous layer metadata).

Here is the code for concatenating the two.

merged_out = tf.keras.layers.concatenate([wide_model.output, deep_model.output])
merged_out = tf.keras.layers.Dense(1)(merged_out)
combined_model = tf.keras.Model(inputs=wide_model.input + [deep_model.input], outputs=merged_out)
print(combined_model.summary())

For each model's inputs, I tried using tf.layers.Inputwith

inputs = tf.placeholder(tf.float32, shape=(None,X_resampled.shape[1]))
deep_inputs = tf.keras.Input(tensor=(inputs))

to make them tf.layers.Input as this page mentions. But I'm still facing the same issue.

I'm using tensorflow==1.10.0

Could someone help me solving this issue?

Thanks!

1

1 Answers

2
votes

In inputs=wide_model.input + [deep_model.input], wide.model.input is probably not a list, so that you are passing a new Add tensor instead of a list of inputs. Try passing inputs=[wide_model.input] + [deep_model.input] instead