Bootstrap

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博客

 

;