我正在尝试在 Keras 中进行多类语义分割。现在我正在使用 Unet 架构,并且有一个与此类似的模型(但更深):
inputs = Input(shape=(512,512,3))
# 128
down1 = Conv2D(32, (3, 3), activation='relu', padding='same')(inputs)
down1 = BatchNormalization()(down1)
down1 = Dropout(0.1)(down1)
down1 = Conv2D(32, (3, 3), padding='same', activation='relu')(down1)
down1 = BatchNormalization()(down1)
down1_pool = MaxPooling2D((2, 2))(down1)
center = Conv2D(64, (3, 3), padding='same', activation='relu')(down1_pool)
center = BatchNormalization()(center)
center = Dropout(0.1)(center)
center = Conv2D(64, (3, 3), padding='same', activation='relu')(center)
center = BatchNormalization()(center)
# center
up1 = concatenate([Conv2DTranspose(32, (2, 2), strides=(2, 2), padding='same')(center), down1], axis=3)
up1 = Conv2D(32, (3, 3), padding='same', activation='relu')(up1)
up1 = BatchNormalization()(up1)
up1 = Dropout(0.1)(up1)
up1 = Conv2D(32, (3, 3), padding='same', activation='relu')(up1)
up1 = BatchNormalization()(up1)
# 128
classify = Conv2D(3, (1, 1), activation='softmax')(up1)
model = Model(inputs=inputs, outputs=classify]
model.compile(optimizer=Adam(lr=lr), loss='categorical_crossentropy, metrics=[losses.dice_coeff])
我的数据集由 680k 个图像(512、512、3)和 680k 个相应的标签组成。标签是 one-hot 编码的并且具有形状 (512, 512, 3) 即 3 个类别。
然后我的问题是:这是设置我的模型的正确方法吗?还是我应该使用“sigmoid”激活和“binary_crossentropy”?