[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
torchvision.transforms.Normalize()中的mean和std参数做什么用呢?
疑问1:
按照我的理解,归一化就是要把图片3个通道中的数据整理到[-1, 1]区间。
x = (x - mean(x))/stddev(x)
只要输入数据集x确定了,mean(x)和stddev(x)也就是确定的数值了,为什么Normalize()函数还需要输入mean和std的数值呢?
疑问2:
RGB单个通道的值不是[0, 255]吗?所以一个通道的均值应该在127附近才对。
如果Normalize()函数按照下面的版式去计算 x = (x - mean)/std 因为RGB是[0, 255],算出来的x就不可能落在[-1,
1]区间了。
疑问3:
可我看很多代码里面是这样的:
torchvision.transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229,
0.224, 0.225])
这一组值是怎么来的? 为什么这三个通道的均值都是小于1的值呢?
1、
mean 和 std 肯定要在normalize之前自己先算好再传进去的,不然每次normalize程序就得把所有的图片都读取一遍算这两个数…
2、有两种情况:
a)如果是imagenet数据集,那么ImageNet的数据在加载的时候就已经转换成了[0, 1].
b)应用了torchvision.transforms.ToTensor,其作用是
( Converts a PIL Image or numpy.ndarray (H x W x C) in the range [0, 255] to
a torch.FloatTensor of shape (C x H x W) in the range [0.0, 1.0] )
3、[0.485, 0.456, 0.406]这一组平均值是从imagenet训练集中抽样算出来的。