背景
pytorch中有很多在ImageNet上训练得到的预训练模型,可以拿来做迁移学习(如下图)。但是使用的时候需要注意,如果想得到最佳的效果以及最快的收敛速度,那么迁移学习的时候,预处理部分需要和这些模型在ImageNet上训练的时候保持一直。
对应的预处理
以上的模型在ImageNet上训练时,对图像使用的预处理是
- channe的顺序是 RGB(不是BGR)
- tensor的维度顺序是 C ✖️ H ✖️ W
- 像素值归一化到0~1
- 减去均值:[0.485, 0.456, 0.406]
- 除以标准差:[0.229, 0.224, 0.225]
原文
All pre-trained models expect input images normalized in the same way, i.e. mini-batches of 3-channel RGB images of shape (3 x H x W), where H and W are expected to be at least 224. The images have to be loaded in to a range of [0, 1] and then normalized using mean = [0.485, 0.456, 0.406] and std = [0.229, 0.224, 0.225]. You can use the following transform to normalize:
参考:https://pytorch.org/vision/stable/models.html#classification