首页 文章

如何使用notop图层对tensorflow进行微调并定义我自己的输入图像大小

提问于
浏览
1

有很多关于如何使用tensorflow进行微调的例子 . 几乎所有这些示例都尝试将我们的图像调整为现有模型所需的指定大小 . 例如,224×224是vgg19所需的输入大小 . 但是,在keras中,我们可以通过将include_top设置为false来更改输入大小:

base_model = VGG19(include_top=False, weights="imagenet", input_shape=(input_size, input_size, input_channels))

然后我们不再需要将图像大小固定为224×224 . 我们可以通过使用tensorflow中的官方预训练模型进行这种微调吗?到目前为止我找不到解决方案,有人帮助我吗?

1 回答

  • 1

    是的,可以进行这种微调 . 您必须确保除了最后几层(以考虑更改的输出)之外,还要微调原始网络的前几个层中的一些(以考虑更改的输入) .

    我使用Keras与TensorFlow合作 . 如果您对此持开放态度,那么会有一个代码片段,其中显示了一般的微调流程:

    https://keras.io/applications/

    具体来说,我必须编写以下代码以使其适用于我的情况:

    #img_width,img_height is the size of your new input, 3 is the number of channels
    input_tensor = Input(shape=(img_width, img_height, 3))
    base_model = 
    keras.applications.vgg19.VGG19(include_top=False,weights='imagenet', input_tensor=input_tensor)
    #instantiate whatever other layers you need
    model = Model(inputs=base_model.inputs, outputs=predictions)
    #predictions is the new logistic layer added to account for new classes
    

    希望这可以帮助 .

相关问题