gpt4 book ai didi

machine-learning - 使用具有不同输入形状和类模型的预训练模型

转载 作者:行者123 更新时间:2023-11-30 08:27:54 31 4
gpt4 key购买 nike

我正在使用 CNN 处理分类问题,其中我的输入图像大小为 64X64,并且我想使用预训练模型,例如 VGG16COCO 或任何其他。但问题是预训练模型的输入图像大小为224X224。我该如何排序这个问题。有没有针对输入图像大小的数据增强方法。

如果我将输入图像的大小调整为 224X224,那么图像很可能会变得模糊,这可能会影响训练。如果我错了,请纠正我。

另一个问题与预训练模型有关。如果我使用迁移学习,那么通常我必须如何从预训练模型中卡住层。考虑到我的分类与预训练的模型类有很大不同。但我想我们可以卡住前几层来获取图像的边缘、曲线等,这在所有图像中都很常见。

最佳答案

But the problem is input image size of pretrained model is 224X224.

我假设您使用 Keras/Tensorflow (其他深度学习框架也是如此)。根据 Keras Application 中的文档:

input_shape: optional shape tuple, only to be specified if include_topis False (otherwise the input shape has to be (224, 224, 3) (with'channels_last' data format) or (3, 224, 224) (with 'channels_first'data format). It should have exactly 3 inputs channels, and width andheight should be no smaller than 48. E.g. (200, 200, 3) would be one

因此有两种选择可以解决您的问题:

  1. 将输入图像的大小调整为 244*244 existing library并使用 VGG 分类器 [include_top=True]。

  2. 在 VGG 模型之上训练您自己的分类器。正如 Keras 中的上述文档所述,如果您的图像不同于 244*244,则应该训练自己的分类器[include_top=False]。您可以通过以下方式轻松完成此类操作:

     inp = keras.layers.Input(shape=(64, 64, 3), name='image_input')

    vgg_model = VGG19(weights='imagenet', include_top=False)
    vgg_model.trainable = False

    x = keras.layers.Flatten(name='flatten')(vgg_model)
    x = keras.layers.Dense(512, activation='relu', name='fc1')(x)
    x = keras.layers.Dense(512, activation='relu', name='fc2')(x)
    x = keras.layers.Dense(10, activation='softmax', name='predictions')(x)
    new_model = keras.models.Model(inputs=inp, outputs=x)
    new_model.compile(optimizer='adam', loss='categorical_crossentropy',
    metrics=['accuracy'])

If I am using transfer learning then generally how layers I have tofreeze from pretrained model

这实际上取决于您的新任务、您有多少训练示例、您的预训练模型是什么以及许多其他因素。如果我是你,我首先扔掉预训练的模型分类器。然后,如果不起作用,请删除其他一些卷积层并逐步执行,直到获得良好的性能。

关于machine-learning - 使用具有不同输入形状和类模型的预训练模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52130833/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com