【问题标题】:RuntimeError: shape '[100, 1, 28, 28]' is invalid for input of size 62720RuntimeError: shape '[100, 1, 28, 28]' 对于大小为 62720 的输入无效
【发布时间】:2020-07-08 12:56:10
【问题描述】:

PyTorch

我正在尝试在我自己的数据集上构建 CNN,该数据集有 39 个不同的类。

我遇到一个运行时错误

错误


RuntimeError                              Traceback (most recent call last)
<ipython-input-42-67f1329ebfd8> in <module>()
     16         images, labels = images.to(device), labels.to(device)
     17 
---> 18         train = Variable(images.view(100, 1, 28, 28))
     19         labels = Variable(labels)
     20 

RuntimeError: shape '[100, 1, 28, 28]' is invalid for input of size 62720

RuntimeError: shape '[100, 1, 28, 28]' 对于大小为 62720 的输入无效。

【问题讨论】:

    标签: python pytorch conv-neural-network


    【解决方案1】:

    如果您的图像是 28x28,那么您的 batch_size 可能是 80 而不是 100。

    train = Variable(images.view(80, 1, 28, 28))
    

    【讨论】:

    • RuntimeError: shape '[80, 1, 28, 28]' 对于大小为 31360 的输入无效
    • @Hassan 那么你有不同尺寸的图像,或者你的最后一批有不同数量的样本
    猜你喜欢
    • 2020-09-03
    • 1970-01-01
    • 2022-01-15
    • 1970-01-01
    • 1970-01-01
    • 2021-08-02
    • 1970-01-01
    • 2021-12-16
    • 2022-06-28
    相关资源
    最近更新 更多