我正在尝试在图像中分割5个对象的过程中出现图像分割问题。我正在使用U-net体系结构。我的最后一层看起来像这样:
conv_final = Conv2D(OUTPUT_MASK_CHANNELS, (1, 1))(up_conv_224)
conv_final = Activation('sigmoid')(conv_final)
model = Model(inputs, conv_final, name="ZF_UNET_224")
但是我收到一条错误消息:
ValueError:检查目标时出错:预期conv2d_24具有形状(224,224,5)但得到形状为(224,224,3)的数组
这是我正在使用的生成器
image_generator = train_datagen.flow_from_directory(
'data/train', # this is the target directory
target_size=(224, 224),
color_mode = 'rgb',# all images will be resized to 150x150
batch_size=batch_size,
class_mode=None,
seed = 1) # since we use binary_crossentropy loss, we need binary labels
# this is a similar generator, for validation data
mask_generator = mask_datagen.flow_from_directory(
'data/train',
target_size=(224, 224),
color_mode = 'rgb',
batch_size=batch_size,
class_mode=None,
seed = 1)
train_generator = zip(image_generator, mask_generator)
该如何解决?任何帮助表示赞赏!
答案 0 :(得分:0)
您必须将数据转换为一种热编码格式。
使用from keras.utils import to_categorical