为什么ToTensor()没有实现文档中所述的归一化?是bug?

ToTensor()的中文文档解释如下:
把一个取值范围是[0,255]的PIL.Image或者shape为(H,W,C)的numpy.ndarray,转换成形状为[C,H,W],取值范围是[0,1.0]的torch.FloadTensor
以下是中文文档给出的官方实例:
data = np.random.randint(0, 255, size=300)
img = data.reshape(10,10,3)
print(img.shape)
img_tensor = transforms.ToTensor()(img) # 转换成tensor
print(img_tensor)

运行结果
(10, 10, 3)
tensor([[[161, 112, 92, 251, 17, 13, 193, 14, 33, 91],
[203, 8, 215, 184, 245, 127, 49, 241, 162, 149],
[189, 27, 147, 79, 196, 220, 233, 24, 54, 148],
[207, 10, 239, 222, 189, 89, 58, 220, 251, 99],
[136, 8, 112, 54, 154, 161, 109, 172, 142, 228],
[121, 156, 174, 17, 216, 102, 55, 254, 40, 206],
[208, 173, 209, 81, 145, 250, 139, 108, 239, 44],
[ 40, 23, 84, 104, 212, 78, 25, 48, 221, 182],
[ 71, 20, 246, 200, 78, 80, 127, 134, 120, 216],
[ 60, 141, 83, 205, 134, 222, 17, 33, 235, 6]],

[[169, 208, 143, 176, 130, 3, 242, 88, 100, 120],
[ 40, 120, 220, 140, 113, 125, 62, 16, 83, 151],
[ 89, 130, 152, 197, 106, 10, 149, 94, 81, 90],
[225, 77, 86, 85, 165, 147, 188, 223, 214, 22],
[164, 214, 184, 19, 132, 201, 68, 153, 82, 104],
[219, 70, 43, 173, 138, 94, 110, 88, 169, 169],
[ 7, 132, 204, 56, 60, 92, 223, 106, 140, 1],
[138, 171, 26, 132, 8, 232, 14, 40, 11, 33],
[168, 65, 118, 168, 165, 115, 229, 173, 170, 34],
[ 22, 93, 107, 171, 58, 10, 121, 200, 131, 45]],

[[ 77, 17, 204, 36, 160, 53, 193, 143, 29, 69],
[229, 19, 223, 167, 93, 87, 103, 36, 196, 188],
[117, 88, 25, 193, 205, 114, 3, 118, 122, 112],
[184, 18, 136, 16, 61, 174, 214, 180, 17, 53],
[167, 132, 127, 28, 254, 9, 118, 4, 205, 219],
[ 67, 51, 229, 36, 236, 85, 185, 47, 212, 228],
[137, 242, 233, 154, 119, 215, 161, 203, 192, 49],
[ 26, 209, 109, 210, 221, 180, 89, 137, 233, 126],
[195, 40, 110, 234, 148, 108, 175, 234, 26, 29],
[233, 52, 253, 36, 225, 155, 228, 41, 60, 244]]],
dtype=torch.int32)
没有实现归一化啊,怎么回事???
已邀请:

信陵君

赞同来自:

取值范围并不是文档中所说的-----范围是[0,1.0],这是怎么回事????

golemz

赞同来自:

中文文档是老版本的,过时了吧,现在的版本是用transforms.Normalize(mean, std)归一化,mean是均值,std是标准差

zfpxs

赞同来自:

你把类型改成byte,或者numpy的uint8试试

要回复问题请先登录注册