drop_last=True

drop_last=True
当你使用了batch normalization的时候,如果batch_size设置得不合适,又没有使用 drop_last = true,那么可能会遇到以下错误

Expected more than 1 value per channel when training, got input size torch.Size([1, 1024])

解决方案:

https://discuss.pytorch.org/t/about-the-relation-between-batch-size-and-length-of-data-loader/10510/4

train_iter = torch.utils.data.DataLoader(train_dataset, batch_size = batch_size, shuffle = True, num_workers = num_workers, drop_last=True)

test_iter = torch.utils.data.DataLoader(test_dataset, batch_size = batch_size, shuffle = True, num_workers = num_workers, drop_last=True)

使用了drop_last = True, 可能会有以下后果:

比如 test set中有229个数据, 如果batch size = 40, 那么就会有29个数据不会被使用。在每一个epoch中,就只有200个数据。229 - 40*5 = 29

再比如,batch size = 20, 那么就会有9个数据不会被使用。在每一个epoch中,就只有220个数据。 229 - 20*11 = 9
作者:宿安雅
https://www.bilibili.com/read/cv4956521/
出处: bilibili

  • 14
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值