在微调预训练的模型时在Keras中预处理图像的正确方法是什么

问题描述:

在Keras中预处理数据同时微调keras中预先训练好的模型的正确方法是什么?应用程序中我们自己的数据?

What is the right way to preprocess the data in Keras while fine-tuning the pre-trained models in keras.applications for our own data?

Keras提供了以下 preprocess_input 函数

Keras provides the following preprocess_input functions

keras.applications.imagenet_utils.preprocess_input

keras.applications.inception_v3.preprocess_input

keras.applications.xception.preprocess_input

keras.applications.inception_resnet_v2.preprocess_input

看在inception_v3,xception和inception_resnet_v2中,它调用 keras.applications.imagenet_utils.preprocess_input mode ='tf'。对于其他模型,它会设置 mode ='caffe',每个模型都执行不同的转换。

Looking inside it seems like for inception_v3, xception, and inception_resnet_v2, it calls keras.applications.imagenet_utils.preprocess_input with mode='tf'. While for other models it sets mode='caffe' each of which perform a different transformation.

在有关从弗朗索瓦·霍莱特(Francois chollet)进行迁移学习的博客文章中- https://blog.keras.io/building-powerful-image-classification-models-using-very-little-data.html -通过除以255的标准将其归一化为 [0,1] 。不应该使用Keras中的preprocess_input函数吗?

In the blog post about transfer learning from Francois chollet -- https://blog.keras.io/building-powerful-image-classification-models-using-very-little-data.html -- it is normalized to [0, 1] through a division with 255. Shouldn't the preprocess_input functions in Keras be used instead?

也不清楚输入的图像是RGB还是BGR?

Also it is not clear whether the input images should be in RGB or BGR? Is there any consistency regarding this or is it specific to the pre-trained model being used?

始终使用 preprocess_input 函数。也就是说,对于 InceptionV3 keras.applications使用 keras.applications.inception_v3.preprocess_input 。 resnet50.preprocess_input 用于 ResNet50

Always use the preprocess_input function in the corresponding model-level module. That is, use keras.applications.inception_v3.preprocess_input for InceptionV3 and keras.applications.resnet50.preprocess_input for ResNet50.

模式参数指定训练原始模型时使用的预处理方法。 mode ='tf'表示预训练权重是从TF转换而来的,其中作者使用 [-1,1] ,c来训练模型。 code>输入范围。 mode ='caffe' mode ='torch'也是如此。

The mode argument specifies the preprocessing method used when training the original model. mode='tf' means that the pre-trained weights are converted from TF, where the authors trained model with [-1, 1] input range. So are mode='caffe' and mode='torch'.

应用程序的输入。*。preprocess_input 始终为RGB。如果模型期望输入BGR,则将在 preprocess_input 内部置换通道。

The input to applications.*.preprocess_input is always RGB. If a model expects BGR input, the channels will be permuted inside preprocess_input.

您提到的博客文章是在引入 keras.applications 模块之前发布的。我不建议将它用作 keras.applications 的转移学习的参考。也许最好在 docs 中尝试这些示例。

The blog post you've mentioned was posted before the keras.applications module was introduced. I wouldn't recommend using it as a reference for transfer learning with keras.applications. Maybe it'll be better to try the examples in the docs instead.