createAugmenter()不能输出灰度化的单通道数据应该怎么解决?

看了下createAugmenter()的文档说明
rand_gray (float) – [0, 1], probability to convert to grayscale for all channels, the number of channels will not be reduced to 1
即便灰度化也不能将通道缩减为单通道,所以要自己手动添加一个处理的部分?

另外在之前cifar10的示例中,mean和std又是如何选择的呢?通常的处理不应该是零均值,1标准差吗?
mean=np.array([0.4914, 0.4822, 0.4465]), std=np.array([0.2023, 0.1994, 0.2010]))
@mli 谢谢。

你需要单通道的可以手动slice到单通道

mean和std是实际图片算出来的,计算的时候通过 (x-mean)/std将输入x变成零均值,1标准差

1赞

恩,读取了一下灰度图片,发现三个通道的数值是相同的。(本来还以为要用公式转换一下)
虽然用切片也能得到想要的数据,不过感觉内存占用可能还是个问题。

import mxnet as mx
r = 0 # r mean
g = 0 # g mean
b = 0 # b mean
r_2 = 0 # r^2
g_2 = 0 # g^2
b_2 = 0 # b^2
total = 0
import os
img_path = "./data/kaggle_cifar10/train/"
img_list = os.listdir(img_path)
for img_name in img_list:
    img = mx.image.imread(img_path + "/" + img_name) # ndarray, width x height x 3
    img = img.astype('float32') / 255.
    total += img.shape[0] * img.shape[1]

    r += img[:, :, 0].sum().asscalar()
    g += img[:, :, 1].sum().asscalar()
    b += img[:, :, 2].sum().asscalar()

    r_2 += (img[:, :, 0]**2).sum().asscalar()
    g_2 += (img[:, :, 1]**2).sum().asscalar()
    b_2 += (img[:, :, 2]**2).sum().asscalar()
r_mean = r / total
g_mean = g / total
b_mean = b / total
r_var = r_2 / total - r_mean ** 2
g_var = g_2 / total - g_mean ** 2
b_var = b_2 / total - b_mean **2

例子里面的是 [0.4914, 0.4822, 0.4465], [0.2023, 0.1994, 0.2010])

print("[",r_mean,",",g_mean,",",b_mean,"]")
[ 0.49139968975309284 , 0.4821584195986949 , 0.4465309242176637 ]
import math
print("[",math.sqrt(r_var),",",math.sqrt(g_var),",",math.sqrt(b_var),"]")
[ 0.24703223678232347 , 0.24348513216263187 , 0.26158784565131554 ]

用https://discuss.gluon.ai/t/topic/4094/2给的代码算了算,确实可以得到相同的mean,但是std似乎是来自另外的数据集?

2赞

标准差是不是要除以 (n-1),这里是除以 n

std的确算不出来, 而且你上面代码应该明显 不是var公式吧