MNIST,Torchvision中的输出和广播形状不匹配

时间:2019-03-12 14:51:34

标签: python pytorch mnist torchvision

在Torchvision中使用MNIST数据集时出现以下错误

RuntimeError: output with shape [1, 28, 28] doesn't match the broadcast shape [3, 28, 28]

这是我的代码:

import torch
from torchvision import datasets, transforms

transform = transforms.Compose([transforms.ToTensor(),
                            transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)),
                          ])
trainset = datasets.MNIST('~/.pytorch/MNIST_data/', download=True, train=True, transform=transform)
trainloader = torch.utils.data.DataLoader(trainset, batch_size=64, shuffle=True)
images, labels = next(iter(trainloader))

1 个答案:

答案 0 :(得分:8)

该错误是由于数据集的颜色与灰度之间的关系,数据集是灰度的。

我通过将transform更改为

来修复它
$('#thedate').datepicker({minDate:0});

$('#checkDate').bind('click', function() {
    var selectedDate = $('#thedate').datepicker('getDate');

    var current = moment(selectedDate);
    if (moment().month()== current.month()) {
        alert('this month');
    } else {
        alert('Not this  month');
    }
});