简体   繁体   English

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

[英]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_inputInceptionV3keras.applications.resnet50.preprocess_inputResNet50

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.

相关问题 如何使用预训练模型进行文本分类?比较经过微调的 model 与未经微调的预训练 model - How to use pre-trained models for text classification?Comparing a fine-tuned model with a pre-trained model without fine-tuning 在从预训练模型进行微调后,丢失TensorFlow模型中的输出节点名称 - Losing output node names in TensorFlow model after fine-tuning from pre-trained model 猫图像的 Keras 自动编码器的微调 - Fine-tuning of Keras autoencoders of cat images Keras 中的预训练模型,TorchVision - Pre-Trained Models in Keras,TorchVision 数据集训练:融合参数调整和预训练模型 - dataset training: converging on parameter tuning and pre-trained models Keras:在imagenet上获取预训练模型的标签名称 - Keras: get labels name of pre-trained models on imagenet 在 Keras 中使用 fasttext 预训练模型作为嵌入层 - Using fasttext pre-trained models as an Embedding layer in Keras 在应用程序中使用预训练模型的硬件要求是什么? - What are the hardware requirements for the use of pre-trained models in applications? 当使用TensorFlow slim调整预训练模型时,如何知道要排除或训练的范围? - How to know which scopes to exclude or to train when fine tuning a pre-trained model with TensorFlow slim? 在 Keras 中嵌入预训练模型的问题 - Issue with embedding pre-trained model in Keras
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM