'Multi input problem Keras. Expected to see 2 array(s), but instead got the following list of 1 arrays
I have a model that takes two inputs of the same shape (batch_size,512,512,1)
, and predict two masks each of shape (batch_size,512,512,1)
.
dataset_input = tf.data.Dataset.zip((dataset_img_A, dataset_img_B))
dataset_output = tf.data.Dataset.zip((seg_A, seg_B))
dataset = tf.data.Dataset.zip((dataset_input, dataset_output))
dataset = dataset.repeat()
dataset = dataset.batch(batch_size, drop_remainder=True)
I'm creating a model like so:
image_inputs_A = layers.Input((512,512,1), batch_size=self.batch_size)
image_inputs_B = layers.Input((512,512,1), batch_size=self.batch_size)
output_A = some_layers(image_inputs_A)
output_B = some_layers(image_inputs_B)
model = models.Model([image_inputs_A, image_inputs_B],[output_A, output_B])
However I'm getting the following error
ValueError: Error when checking model input: the list of Numpy arrays that you are passing to your model is not the size the model expected. Expected to see 2 array(s), but instead got the following list of 1 arrays: [<tf.Tensor 'IteratorGetNext:0' shape=(?, 2, ?, ?, ?) dtype=float32>]...
It seems that its concatenating the inputs to (batch_size,2,512,512,1)
, instead of listing them as a tuple of two tensors (batch_size,512,512,1 )
. Is this the expected behaviour? How can I use multiple inputs without them concatenating?
EDIT:
I have tried to use an layers.Input with shape (batch_size, 2, 512, 512, 1)
and then pass through two lambda layers to split the tensor along the second axis, however.. I get the following error
ValueError: Error when checking input: expected input_1 to have 5 dimensions, but got array with shape (None, None, None, None)
EDIT 2:
I've double checked the data im inputing into the model.
INPUT: (512, 512, 1) <dtype: 'float32'> INPUT: (512, 512, 1) <dtype: 'float32'> OUTPUT: (512, 512, 1) <dtype: 'int64'> OUTPUT: (512, 512, 1) <dtype: 'int64'>
Solution 1:[1]
SOLVED: Turns out it was an issue with the data augmentation step where tensors where concatenated inputs. Lesson learnt
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | noble_kazoo |