1
使用unsqueeze():Torch中的view()和unsqueeze()有什么区别?
使用 view()input = torch.Tensor(2, 4, 3) # input: 2 x 4 x 3
print(input.unsqueeze(0).size()) # prints - torch.size([1, 2, 4, 3])
:
input = torch.Tensor(2, 4, 3) # input: 2 x 4 x 3
print(input.view(1, -1, -1, -1).size()) # prints - torch.size([1, 2, 4, 3])
据文档,unsqueeze()插入单暗淡在给定的参数和view()位置创建具有相关联的存储的不同的尺寸的图tensor
。
view()对我来说很清楚,但我无法区分它与unsqueeze()。此外,我不明白何时使用view()以及何时使用unsqueeze()?
任何帮助与良好的解释将不胜感激!