ValueError: Expected more than 1 value per channel when training, got input size torch.Size([1, 512,

Traceback (most recent call last):                                                                          
  File "E:\Anaconda\envs\opencv\lib\runpy.py", line 194, in _run_module_as_main                             
    return _run_code(code, main_globals, None,                                                              
  File "E:\Anaconda\envs\opencv\lib\runpy.py", line 87, in _run_code                                        
    exec(code, run_globals)                                                                                 
  File "E:\Anaconda\envs\opencv\Scripts\yolo.exe\__main__.py", line 7, in <module>                          
  File "E:\Anaconda\envs\opencv\lib\site-packages\ultralytics\cfg\__init__.py", line 448, in entrypoint     
    getattr(model, mode)(**overrides)  # default args from model                                            
  File "E:\Anaconda\envs\opencv\lib\site-packages\ultralytics\engine\model.py", line 356, in train
  File "E:\Anaconda\envs\opencv\lib\site-packages\torch\nn\functional.py", line 2416, in _verify_batch_size
    raise ValueError("Expected more than 1 value per channel when training, got input size {}".format(size))
ValueError: Expected more than 1 value per channel when training, got input size torch.Size([1, 512, 1, 1])

问题分析: 模型中用了batchnomolization,训练中用batch训练的时候,应该是有单数,比如dataset的总样本数为17,你的batch_size为8,就会报这样的错误。
解决方案: 从dataset中删掉一个sample。即需要保证dataset%batch不等于1

原文链接:【Pytorch】报错:ValueError: Expected more than 1 value per channel when training, got input size [1, 768_raise valueerror("expected more than 1 value per c-CSDN博客

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
该错误通常表示在训练过程中,输入数据的通道数不满足模型的要求。你提供的错误信息中的torch.Size([1, 64, 1, 1])表示输入数据的维度是1个样本,每个样本有64个通道,每个通道的大小是1x1。模型期望每个通道至少有多于一个的值。 解决这个问题的方法是检查你的输入数据和模型的结构是否匹配。可能需要调整数据的通道数或者调整模型的输入层。 引用和引用中提到了相同的错误信息,但没有提供具体的解决方法。因此,我建议你查看引用中的解决方式总结,其中可能提供了解决这个问题的具体方法。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [ValueError: Expected more than 1 value per channel when training, got input size torch.Size([1,](https://blog.csdn.net/weixin_47725177/article/details/128460187)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [python报错系列(7)--ValueError: Expected more than 1 value perchannel when training, got input size ....](https://blog.csdn.net/qq_45365214/article/details/122670591)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值