我正在尝试使用TensorFlow训练分割U-Net。数据集,即我计算机上的图像,在运行模型之前进行了预处理,并保存为Tfrecords。
所以在训练之前,我用tf.data
加载tfrecords。如果我看一个例子,我会得到:
ds_train = tf.data.TFRecordDataset(training_tfrecords).map(load_image_train, num_parallel_calls=tf.data.experimental.AUTOTUNE)
train_dataset = ds_train.cache().shuffle(BUFFER_SIZE).batch(BATCH_SIZE).repeat()
one_record = train_dataset.take(1)
for i, (img, seg) in enumerate(one_record):
print(f"BatchImg{i}: {img.shape}")
print(f"BatchSeg{i}: {seg.shape}")
输出(6=批次大小,96=img尺寸,1=通道尺寸(:
BatchImg0: (6, 96, 96, 96, 1)
BatchSeg0: (6, 96, 96, 96, 1)
到目前为止,它看起来不错。但当我试图开始训练时,我出现了以下错误:
model_history = model.fit(train_dataset, epochs=EPOCHS, steps_per_epoch=180)
输出:
ValueError: logits and labels must have the same shape ((None, 96, 96, 96, 16) vs (None, None, None, None, 1))
我不知道如何在这里进一步调试。。。谢谢你的帮助!
正如Andrey所指出的(谢谢!(,我不仅需要检查我的输入图像形状,还需要检查模型(logits(形状的输出。这个问题只是来自logits和分割之间的形状差异("16"与最后一个维度的1(。所以模型输出不正确。修复后(使用model.summary()
找出该怎么做(,一切都很好!