celebA数据集的mean和std计算结果

celebA数据集的mean和std计算结果

  1. mean: (0.50612009, 0.42543493, 0.38282761)
  2. std: (0.26589054, 0.24521921, 0.24127836)

另附计算代码

import numpy as np
import cv2
import os

path = './img_align_celeba'
means = [0, 0, 0]
stdevs = [0, 0, 0]

index = 1
num_imgs = 0
img_names = os.listdir(path)
for img_name in img_names:
    num_imgs += 1
    print(img_name)
    img = cv2.imread(os.path.join(path, img_name))
    img = np.asarray(img)
    img = img.astype(np.float32) / 255.
    for i in range(3):
        means[i] += img[:, :, i].mean()
        stdevs[i] += img[:, :, i].std()
print(num_imgs)
means.reverse()
stdevs.reverse()

means = np.asarray(means) / num_imgs
stdevs = np.asarray(stdevs) / num_imgs

print("normMean = {}".format(means))
print("normStd = {}".format(stdevs))
print('transforms.Normalize(normMean = {}, normStd = {})'.format(means, stdevs))

你可能感兴趣的:(AI,人工智能,计算机视觉,cv,python)