[英]What is the right way to preprocess images in Keras while fine-tuning pre-trained models
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中预处理数据的正确方法,同时在keras.applications中为我们自己的数据微调预先训练的模型?
Keras provides the following preprocess_input
functions Keras提供以下
preprocess_input
函数
keras.applications.imagenet_utils.preprocess_input keras.applications.imagenet_utils.preprocess_input
keras.applications.inception_v3.preprocess_input keras.applications.inception_v3.preprocess_input
keras.applications.xception.preprocess_input keras.applications.xception.preprocess_input
keras.applications.inception_resnet_v2.preprocess_input keras.applications.inception_resnet_v2.preprocess_input
Looking inside it seems like for inception_v3, xception, and inception_resnet_v2, it calls keras.applications.imagenet_utils.preprocess_input with mode='tf'
. 在内部看来,似乎对于inception_v3,xception和inception_resnet_v2,它使用
mode='tf'
调用keras.applications.imagenet_utils.preprocess_input 。 While for other models it sets mode='caffe'
each of which perform a different transformation. 而对于其他模型,它设置
mode='caffe'
每个模型执行不同的转换。
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? 在关于从Francois chollet转移学习的博客文章中 - https://blog.keras.io/building-powerful-image-classification-models-using-very-little-data.html - 将其归一化为
[0, 1]
通过255的除法。不应该使用Keras中的preprocess_input函数吗?
Also it is not clear whether the input images should be in RGB or BGR? 还不清楚输入图像应该是RGB还是BGR? Is there any consistency regarding this or is it specific to the pre-trained model being used?
是否有任何关于此的一致性,还是特定于使用的预训练模型?
Always use the preprocess_input
function in the corresponding model-level module. 始终在相应的模型级模块中使用
preprocess_input
函数。 That is, use keras.applications.inception_v3.preprocess_input
for InceptionV3
and keras.applications.resnet50.preprocess_input
for ResNet50
. 也就是说,使用
keras.applications.inception_v3.preprocess_input
为InceptionV3
和keras.applications.resnet50.preprocess_input
为ResNet50
。
The mode
argument specifies the preprocessing method used when training the original model. mode
参数指定训练原始模型时使用的预处理方法。 mode='tf'
means that the pre-trained weights are converted from TF, where the authors trained model with [-1, 1]
input range. mode='tf'
表示预训练的权重是从TF转换的,其中作者用[-1, 1]
输入范围训练模型。 So are mode='caffe'
and mode='torch'
. 因此,
mode='caffe'
和mode='torch'
。
The input to applications.*.preprocess_input
is always RGB. applications.*.preprocess_input
的输入applications.*.preprocess_input
始终为RGB。 If a model expects BGR input, the channels will be permuted inside preprocess_input
. 如果模型需要BGR输入,则通道将在
preprocess_input
内置换。
The blog post you've mentioned was posted before the keras.applications
module was introduced. 您提到的博客文章是在引入
keras.applications
模块之前发布的。 I wouldn't recommend using it as a reference for transfer learning with keras.applications
. 我不建议使用它作为
keras.applications
转移学习的参考。 Maybe it'll be better to try the examples in the docs instead. 也许在文档中尝试示例会更好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.