多输入问题 Keras。预期会看到 2 个数组,但却得到了以下 1 个数组的列表
Multi input problem Keras. Expected to see 2 array(s), but instead got the following list of 1 arrays
我有一个模型接受两个相同形状 (batch_size,512,512,1)
的输入,并预测每个形状 (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)
我正在创建这样的模型:
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])
但是我收到以下错误
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>]...
它似乎将输入连接到 (batch_size,2,512,512,1)
,而不是将它们列为两个张量 (batch_size,512,512,1 )
的元组。这是预期的行为吗?如何在不连接的情况下使用多个输入?
编辑:
我尝试使用形状为 (batch_size, 2, 512, 512, 1)
的 layers.Input,然后通过两个 lambda 层以沿第二个轴拆分张量,但是……我收到以下错误
ValueError: Error when checking input: expected input_1 to have 5 dimensions, but got array with shape (None, None, None, None)
编辑 2:
我已经仔细检查了输入模型的数据。
INPUT: (512, 512, 1) <dtype: 'float32'> INPUT: (512, 512, 1) <dtype: 'float32'> OUTPUT: (512, 512, 1) <dtype: 'int64'> OUTPUT: (512, 512, 1) <dtype: 'int64'>
已解决:事实证明这是张量连接输入的数据增强步骤的问题。经验教训
我有一个模型接受两个相同形状 (batch_size,512,512,1)
的输入,并预测每个形状 (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)
我正在创建这样的模型:
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])
但是我收到以下错误
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>]...
它似乎将输入连接到 (batch_size,2,512,512,1)
,而不是将它们列为两个张量 (batch_size,512,512,1 )
的元组。这是预期的行为吗?如何在不连接的情况下使用多个输入?
编辑:
我尝试使用形状为 (batch_size, 2, 512, 512, 1)
的 layers.Input,然后通过两个 lambda 层以沿第二个轴拆分张量,但是……我收到以下错误
ValueError: Error when checking input: expected input_1 to have 5 dimensions, but got array with shape (None, None, None, None)
编辑 2:
我已经仔细检查了输入模型的数据。
INPUT: (512, 512, 1) <dtype: 'float32'> INPUT: (512, 512, 1) <dtype: 'float32'> OUTPUT: (512, 512, 1) <dtype: 'int64'> OUTPUT: (512, 512, 1) <dtype: 'int64'>
已解决:事实证明这是张量连接输入的数据增强步骤的问题。经验教训