如何将最后一层 mobilenet 的输出提供给 Unet 模型
How can I feed the output from last layer of mobilenet to a Unet model
我正在尝试使用在 imagenet 数据集上预训练的 Keras mobilenet 模型构建图像分割模型。如何进一步训练模型,我想将 U-net 层添加到现有模型中,并且只训练 u-net 架构的层,而 mobilenet 模型作为 backbone.
提供帮助
问题:mobilenet模型最后一层的维度是(7x7x1024),是一个RelU层,我想把它整形为(256x256x3),这样U-net输入层可以理解。
不是最后一层,但是可以使用以下代码在 mobilenet 上创建一个 unet:
ALPHA = 1 # Width hyper parameter for MobileNet (0.25, 0.5, 0.75, 1.0). Higher width means more accurate but slower
IMAGE_HEIGHT = 224
IMAGE_WIDTH = 224
HEIGHT_CELLS = 28
WIDTH_CELLS = 28
def create_model(trainable=True):
model = MobileNet(input_shape=(IMAGE_HEIGHT, IMAGE_WIDTH, 3), include_top=False, alpha=ALPHA, weights="imagenet")
block0 = model.get_layer("conv_pw_1_relu").output
block = model.get_layer("conv_pw_1_relu").output
block1 = model.get_layer("conv_pw_3_relu").output
block2 = model.get_layer("conv_pw_5_relu").output
block3 = model.get_layer("conv_pw_11_relu").output
block4 = model.get_layer("conv_pw_13_relu").output
x = Concatenate()([UpSampling2D()(block4), block3])
x = Concatenate()([UpSampling2D()(x), block2])
x = Concatenate()([UpSampling2D()(x), block1])
x = Concatenate()([UpSampling2D()(x), block])
# x = Concatenate()([UpSampling2D()(x), block0])
x = UpSampling2D()(x)
x = Conv2D(1, kernel_size=1, activation="sigmoid")(x)
x = Reshape((IMAGE_HEIGHT, IMAGE_HEIGHT))(x)
return Model(inputs=model.input, outputs=x)
我正在尝试使用在 imagenet 数据集上预训练的 Keras mobilenet 模型构建图像分割模型。如何进一步训练模型,我想将 U-net 层添加到现有模型中,并且只训练 u-net 架构的层,而 mobilenet 模型作为 backbone.
提供帮助问题:mobilenet模型最后一层的维度是(7x7x1024),是一个RelU层,我想把它整形为(256x256x3),这样U-net输入层可以理解。
不是最后一层,但是可以使用以下代码在 mobilenet 上创建一个 unet:
ALPHA = 1 # Width hyper parameter for MobileNet (0.25, 0.5, 0.75, 1.0). Higher width means more accurate but slower
IMAGE_HEIGHT = 224
IMAGE_WIDTH = 224
HEIGHT_CELLS = 28
WIDTH_CELLS = 28
def create_model(trainable=True):
model = MobileNet(input_shape=(IMAGE_HEIGHT, IMAGE_WIDTH, 3), include_top=False, alpha=ALPHA, weights="imagenet")
block0 = model.get_layer("conv_pw_1_relu").output
block = model.get_layer("conv_pw_1_relu").output
block1 = model.get_layer("conv_pw_3_relu").output
block2 = model.get_layer("conv_pw_5_relu").output
block3 = model.get_layer("conv_pw_11_relu").output
block4 = model.get_layer("conv_pw_13_relu").output
x = Concatenate()([UpSampling2D()(block4), block3])
x = Concatenate()([UpSampling2D()(x), block2])
x = Concatenate()([UpSampling2D()(x), block1])
x = Concatenate()([UpSampling2D()(x), block])
# x = Concatenate()([UpSampling2D()(x), block0])
x = UpSampling2D()(x)
x = Conv2D(1, kernel_size=1, activation="sigmoid")(x)
x = Reshape((IMAGE_HEIGHT, IMAGE_HEIGHT))(x)
return Model(inputs=model.input, outputs=x)