【发布时间】:2017-08-09 13:12:23
【问题描述】:
unsqueeze()的使用:
input = torch.Tensor(2, 4, 3) # input: 2 x 4 x 3
print(input.unsqueeze(0).size()) # prints - torch.size([1, 2, 4, 3])
view()的使用:
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()?
任何有很好解释的帮助将不胜感激!
【问题讨论】: