Python numpy中跨颜色通道的标准化
我有一个numpy数组(10000,32,32,3)(10000个图像,32个像素乘以32个像素,3个颜色通道),我正试图分别规范化最后三个通道中的每一个 要在红色通道上正常化,我尝试使用Python numpy中跨颜色通道的标准化,python,numpy,neural-network,normalization,Python,Numpy,Neural Network,Normalization,我有一个numpy数组(10000,32,32,3)(10000个图像,32个像素乘以32个像素,3个颜色通道),我正试图分别规范化最后三个通道中的每一个 要在红色通道上正常化,我尝试使用 testX[:,:,:,0] = (testX[:,:,:,0]-np.mean(testX[:,:,:,0]))/np.std(testX[:,:,:,0]) 但不是沿着红色列生成标准化输出,例如:(这是其中一幅图像中的最后一行像素) 它将所有红细胞设置为0、1或255 [[ ...,
testX[:,:,:,0] = (testX[:,:,:,0]-np.mean(testX[:,:,:,0]))/np.std(testX[:,:,:,0])
但不是沿着红色列生成标准化输出,例如:(这是其中一幅图像中的最后一行像素)
它将所有红细胞设置为0、1或255
[[
...,
[[ 0, 108, 94],
[255, 37, 21],
[ 0, 136, 127],
...,
[ 0, 172, 114],
[ 0, 204, 141],
[ 1, 182, 118]]]]
这个切片功能缺少什么
有没有更好的方法来实现这一点
既然我正在尝试将其标准化,那么做一些更简单的事情而不是麻烦用颜色标准化会更有意义吗?比如
testX = testX/255
我想知道这是否是由于将最终numpy数组的数据类型设置为int而不是float引起的。请参见以下示例,其中“x”是图像数据:
redchannel = x[:,:,:,0]
greenchannel = x[:,:,:,1]
bluechannel = x[:,:,:,2]
a = 0.0
b = 1.0
imgdata_min = 0
imgdata_max = 255
normalized_redchannel = a + ((( redchannel - imgdata_min)*(b - a))/(imgdata_max - imgdata_min))
# merge channels
x_with_normalized_red = np.stack((normalized_redchannel,greenchannel,bluechannel), axis=3)
print(x_with_normalized_red.astype('int32')) # prints 0/1 values
print(x_with_normalized_red.astype('float32')) # prints floating point values
你所说的标准化输出是什么意思?我认为它在不同的环境中意味着不同的事情。取数据的平均值不是更好吗?我最初是通过使用testX=(testX np.mean(testX))/np.std(testX)来取数据的平均值的,它工作得很好,但我在看,在每种颜色的基础上这样做是否会改善我正在训练的神经网络的学习。通过标准化输出,我指的是减去平均值,然后除以标准偏差,得到正态分布。虽然我已经看到了一些同样有用的规范化,它只涉及将每个数据点除以数组中的最大值
redchannel = x[:,:,:,0]
greenchannel = x[:,:,:,1]
bluechannel = x[:,:,:,2]
a = 0.0
b = 1.0
imgdata_min = 0
imgdata_max = 255
normalized_redchannel = a + ((( redchannel - imgdata_min)*(b - a))/(imgdata_max - imgdata_min))
# merge channels
x_with_normalized_red = np.stack((normalized_redchannel,greenchannel,bluechannel), axis=3)
print(x_with_normalized_red.astype('int32')) # prints 0/1 values
print(x_with_normalized_red.astype('float32')) # prints floating point values