transforms.normize返回值高于255 pytorch
我正在使用视频数据集,将帧读为整数,然后将它们转换为numpy Array Float32。 加载后,它们出现在0到255之间的范围:
[165., 193., 148.],
[166., 193., 149.],
[167., 193., 149.],
...
最后,将它们馈送到我的模型并堆叠框架,我进行了“ Totensor()”加上我的转换[transforms.resiss.resize(224),转换。归一化([[0.454,0.390,0.331],[0.164,0.187,0.152])]
,在这里进行转换和堆叠框架的代码:
res_vframes = []
for i in range(len(v_frames)):
res_vframes.append(self.transforms((v_frames[i])))
res_vframes = torch.stack(res_vframes, 0)
问题是在变换后,值以这种方式出现,该值以这种方式出现,值高于255:
[tensor([[[1003.3293, 1009.4268, 1015.5244, ..., 1039.9147, 1039.9147,
1039.9147],...
对我缺少或做错事的想法?
I am working on an video dataset, I read the frames as integers and convert them to a numpy array float32.
After being loaded, they appear in a range between 0 and 255:
[165., 193., 148.],
[166., 193., 149.],
[167., 193., 149.],
...
Finally, to feed them to my model and stack the frames I do the "ToTensor()" plus my transformation [transforms.Resize(224), transforms.Normalize([0.454, 0.390, 0.331], [0.164, 0.187, 0.152])]
and here the code to transform and stack the frames:
res_vframes = []
for i in range(len(v_frames)):
res_vframes.append(self.transforms((v_frames[i])))
res_vframes = torch.stack(res_vframes, 0)
The problem is that after the transformation the values appears in this way, which has values higher than 255:
[tensor([[[1003.3293, 1009.4268, 1015.5244, ..., 1039.9147, 1039.9147,
1039.9147],...
Any idea on what I am missing or doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
torchvision.transforms.normalize
的行为:由于上述方程式的左图的分子大于1,并且其分母小于1,因此计算值更大。
类
TotenSor()
将张量的值映射到[0,1],仅当满足某些条件时。从官方的Pytorch文档中检查此代码:因此,您需要明确分配张量或与上述条件相匹配。
The behavior of
torchvision.transforms.Normalize
:Since the numerator of the lefthand of the above equation is greater than 1 and the denominator of it is smaller than 1, the computed value gets larger.
The class
ToTensor()
maps a tensor's value to [0, 1] only if some condition is satisfied. Check this code from official Pytorch docs:Therefore you need to divide tensors explicitly or make to match the above condition.
您的标准化使用0-1和0-255之间的值。
您需要将输入帧更改为0-1,或者将标准化向量更改为0-255。
您可以在使用转换之前将框架除以255:
Your normalization uses values between 0-1 and not 0-255.
You need to change your input frames to 0-1 or the normalization vectors to 0-255.
You can divide the frames by 255 before using the transform: