如何计算自己的图片数据集的均值和方差

import numpy as np
import pickle
def load_CIFAR_batch(filename):
    """ load single batch of cifar """
    with open(filename, 'rb') as f:
        datadict = pickle.load(f,encoding='latin1')
        X = datadict['data']
        Y = datadict['labels']
        X = X.reshape(10000, 3, 32,32).transpose(0,2,3,1).astype("float")
        Y = np.array(Y)
        return X, Y
X,Y = load_CIFAR_batch('/home/xm/桌面/thesis_temp/AdaBound-master/demos/cifar10/data/cifar-10-batches-py/test_batch')
img = X
R_means = []
G_means = []
B_means = []
R_stds = []
G_stds = []
B_stds = []
for im in img:
    im_R = im[:,:,0]/255
    im_G = im[:,:,1]/255
    im_B = im[:,:,2]/255
    im_R_mean = np.mean(im_R)
    im_G_mean = np.mean(im_G)
    im_B_mean = np.mean(im_B)
    im_R_std = np.std(im_R)
    im_G_std = np.std(im_G)
    im_B_std = np.std(im_B)
    R_means.append(im_R_mean)
    G_means.append(im_G_mean)
    B_means.append(im_B_mean)
    R_stds.append(im_R_std)
    G_stds.append(im_G_std)
    B_stds.append(im_B_std)
a = [R_means,G_means,B_means]
b = [R_stds,G_stds,B_stds]
mean = [0,0,0]
std = [0,0,0]
mean[0] = np.mean(a[0])
mean[1] = np.mean(a[1])
mean[2] = np.mean(a[2])
std[0] = np.mean(b[0])
std[1] = np.mean(b[1])
std[2] = np.mean(b[2])
print('数据集的RGB平均值为\n[{},{},{}]'.format(mean[0],mean[1],mean[2]))
print('数据集的RGB方差为\n[{},{},{}]'.format(std[0],std[1],std[2]))

 

  • 1
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值