Pytorch ValueError:太多值无法解包(预期2)

时间:2019-12-07 23:19:51

标签: python pytorch google-colaboratory autoencoder

for epoch in range(num_epochs):
for data in dataloader:
    img, _ = data
    img = Variable(img).cpu()
    # ===================forward=====================
    output = model(img)
    loss = distance(output, img)
    # ===================backward====================
    optimizer.zero_grad()
    loss.backward()
    optimizer.step()
# ===================log========================
print('epoch [{}/{}], loss:{:.4f}'.format(epoch+1, num_epochs, loss.data()))

我正在尝试在Colab上运行此代码,但出现此错误

    ---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-18-93f55b0c43c8> in <module>()
      1 for epoch in range(num_epochs):
      2     for data in loader_train:
----> 3         img, _ = data
      4         img = img.view(img.size(0), -1)
      5         img = Variable(img).cuda()

ValueError: too many values to unpack (expected 2)

我在这里检查了几篇文章,建议我添加这一行

dataloader = torch.utils.data.DataLoader(X_Train_torch, batch_size=32, shuffle=False, num_workers=4)

即使这样,我也会遇到相同的错误。有人知道如何解决吗?

PS。在我的训练数据上,有6000张训练图像,每个图像的尺寸均为80x80。

0 个答案:

没有答案