在预处理中用于预训练网络模型的均值和标准差的几种形式

flyfish

形式1

也就是常见的值
RGB顺序

mean= 0.485, 0.456, 0.406  # RGB mean
std = 0.229, 0.224, 0.225  # RGB standard deviation

引用自 Yolov5 v6.2 原始代码

IMAGENET_MEAN = 0.485, 0.456, 0.406  # RGB mean
IMAGENET_STD = 0.229, 0.224, 0.225  # RGB standard deviation

normalize

def normalize(x, mean=IMAGENET_MEAN, std=IMAGENET_STD, inplace=False):
    # Denormalize RGB images x per ImageNet stats in BCHW format, i.e. = (x - mean) / std
    return TF.normalize(x, mean, std, inplace=inplace)

denormalize

def denormalize(x, mean=IMAGENET_MEAN, std=IMAGENET_STD):
    # Denormalize RGB images x per ImageNet stats in BCHW format, i.e. = x * std + mean
    for i in range(3):
        x[:, i] = x[:, i] * std[i] + mean[i]
    return x

形式2

经过计算如下还有其他的值例如

0.485 × 255 = 123.675
0.456 × 255 = 116.28
0.406 × 255 = 103.53

0.229  × 255  =  58.395
0.224  × 255  =  57.12
0.225  × 255  = 57.375

结果是
RGB顺序

mean = [123.675, 116.28, 103.53]
std= [58.395, 57.12, 57.375]

形式3

以上是RGB顺序,如果是BGR顺序就是
或者经过了保留2位小数,结果就是
BGR顺序

mean = (103.94, 116.78, 123.68)
std   = (57.38, 57.12, 58.40)

形式4

有的地方不使用mean和std,有的地方使用的mean和scale
结果如下计算

1 ÷ 58.395 = 0.017124754
1 ÷ 57.12  = 0.017507003
1 ÷ 57.375 = 0.017429194

也就是形式一的值经过如下计算
m e a n r e s u l t = m e a n ⋅ 255 s c a l e r e s u l t = 1 s t d ∗ 255 mean_ {result}=mean\cdot 255 \\ scale_ {result}=\dfrac {1} {std * 255} meanresult=mean255scaleresult=std2551

结果是
RGB顺序

mean = (103.94, 116.78, 123.68)
scale   = ( 0.017124754, 0.017507003, 0.017429194)

有的地方一般是保留几位小数

形式5

std 合并到 conv1 权重中了,std全是1
RGB顺序

mean = [123.675, 116.28, 103.53]
std= [1.0, 1.0, 1.0]
10-09 20:19