【发布时间】:2020-04-16 14:02:56
【问题描述】:
我正在尝试让 cuda 工作,但我需要将我的训练输入更改为张量。当我尝试这样做时,当我尝试将张量列表堆叠到一个张量中时出现错误。
代码
for epoch in:
alst = []
for x, y in loader:
x = torch.stack(x)
#x = torch.Tensor(x)
#x = torch.stack(x).to(device,dtype=float)
x 的形状:张量列表
[tensor([[[0.325],
[ 0.1257],
[ 0.1149],
...,
[-1.572],
[-1.265],
[-3.574]],
]), tensor([1,2,3,4,5]), tensor(6,5,4,3,2])]
我遇到的错误
22 alst = []
23 for x, y in loader:
---> 24 x_list = torch.stack(x)
25 # x = torch.Tensor(x)
26 # x = torch.stack(x).to(device,dtype=float)
RuntimeError: Expected object of scalar type Float but got scalar type Long for sequence element 1 in sequence argument at position #1 'tensors'
不知道我做错了什么。我也试过x = torch.stack(x).to(device,dtype=float),但还是不行。
【问题讨论】: