我最近开始学习图像分割和UNet。我正在尝试进行多类图像分割,其中我有 7 个类,输入是 (256, 256, 3) rgb 图像,输出是 (256, 256, 1) 灰度图像,其中每个强度值对应于一个类。我正在做像素级的softmax。我使用稀疏分类交叉熵以避免进行 One Hot Encoding。
def soft1(x):
return keras.activations.softmax(x, axis = -1)
def conv2d_block(input_tensor, n_filters, kernel_size = 3, batchnorm = True):
x = Conv2D(filters = n_filters, kernel_size = (kernel_size, kernel_size),\
kernel_initializer = 'he_normal', padding = 'same')(input_tensor)
if batchnorm:
x = BatchNormalization()(x)
x = Activation('relu')(x)
x = Conv2D(filters = n_filters, kernel_size = (kernel_size, kernel_size),\
kernel_initializer = 'he_normal', padding = 'same')(input_tensor)
if batchnorm:
x = BatchNormalization()(x)
x = Activation('relu')(x)
return x
def …Run Code Online (Sandbox Code Playgroud)