pytorch如何将Variable数据转化为Tensor数据

求助
如何将Variable数据转化为Tensor数据
sentence_train_idx = torch.LongTensor(sentence_train_idx)
sentence_train_idx = Variable(sentence_train_idx)
sentence_train_vec = embeds(sentence_train_idx)
label_data = all_train_data[1]
label_data = torch.IntTensor(label_data)
label_data = Variable(label_data)

上面是对数据的一些操作Tensor话的操作
 
torch_dataset = Data.TensorDataset(
data_tensor=sentence_train_vec,
target_tensor=label_data,
)
loader = DataLoader(
dataset=torch_dataset,
batch_size=BATCH_SIZE,
shuffle=True,
num_workers=4,
)
上面是将数据放入数据集中
 

for epoch in range(10):
for step, (b_x, b_y) in enumerate(loader):

print(step, "| b_x ", b_x, "| b_y ", b_y, " | epoch ", epoch)

 
上面是提取数据 但是就在这里出了错误

TypeError: batch must contain tensors, numbers, dicts or lists; found <class 'torch.autograd.variable.Variable'>

很着急,求大佬解决
 thc233@yeah.net
已邀请:

thc222 - 95

赞同来自:

torch_dataset = Data.TensorDataset(
data_tensor=sentence_train_vec.data,
target_tensor=label_data.data,
)
把dataset改成上面的就好了
还是太年轻

要回复问题请先登录注册