刚开始使用 Conv Nets 并尝试图像分割问题。我为 dstl 卫星图像特征检测竞赛获得了 24 张图像及其掩码。(https://www.kaggle.com/c/dstl-satellite-imagery-feature-detection/data)
我想我会尝试按照这里的提示https://blog.keras.io/building-powerful-image-classification-models-using-very-little-data.html但我被卡住了。
我下载了 ZF_UNET_224 的预训练权重,这是该问题的第二名获胜者方法。我的图像蒙版包含 5 个对象,所以我弹出了最后一层,而不是这样:
activation_45 (Activation) (None, 224, 224, 32) 0 batch_normalization_44[0][0]
spatial_dropout2d_2 (SpatialDro (None, 224, 224, 32) 0 activation_45[0][0]
conv2d_46 (Conv2D) (None, 224, 224, 1) 33 spatial_dropout2d_2[0][0]
我现在有这个:
activation_45 (Activation) (None, 224, 224, 32) 0 batch_normalization_44[0][0]
spatial_dropout2d_2 (SpatialDro (None, 224, 224, 32) 0 activation_45[0][0]
predictions (Conv2D) (None, 224, 224, 5) 10 conv2d_46[0][0]
我正在尝试遵循 Keras 教程中的确切步骤,但是当我这样做时
my_model.fit_generator( train_generator, steps_per_epoch= 4, epochs=10, validation_data=validation_generator )
我收到一条错误消息说
Output of generator should be a tuple (x, y, sample_weight) or (x, y). Found: [[[[1. 1. 1. ] [1. 1. 1. ] [1. 1. 1. ] … [1. 1. 1. ] [1. 1. 1. ] [1. 1. 1. ]]
我想我想要的是我的 224X224 图像中每个像素的概率,这样我就可以使用它们在原始图像上生成蒙版,但我不知道如何去做。
我有 24 个 8 波段输入图像及其标记 5 个对象的掩码。我想在这些图像上训练这个 U-Net,并在一些测试图像上放置掩码,并评估它们的 IoU 或加权对数损失。有什么帮助吗?
更新:
我正在使用与 Keras 教程中相同的生成器:
batch_size = 4
# this is the augmentation configuration we will use for training
train_datagen = ImageDataGenerator(
rescale=1./255,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True)
# this is the augmentation configuration we will use for testing:
# only rescaling
test_datagen = ImageDataGenerator(
rescale=1./255,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True)
# this is a generator that will read pictures found in
# subfolers of 'data/train', and indefinitely generate
# batches of augmented image data train_generator =
train_datagen.flow_from_directory(
'data/train', # this is the target directory
target_size=(224, 224), # all images will be resized
batch_size=batch_size,
color_mode='rgb',
class_mode=None) # since we use binary_crossentropy loss, we need binary labels
# this is a similar generator, for validation data
validation_generator = test_datagen.flow_from_directory(
'data/valid',
target_size=(224, 224),
batch_size=batch_size,
color_mode = 'rgb',
class_mode=None)
还有一件事:我的训练图像有 8 个波段,但架构只接受 3 个波段。我认为生成器最后只留下 1 个波段。也不知道如何解决这个问题。