RuntimeError: CUDA out of memory. Tried to allocate

在这里插入图片描述

python train.py --img 640 --batch 16 --epochs 5 --data coco128.yaml --weights yolov5s.pt

把batchsize改小

python train.py --img 640 --batch 2 --epochs 5 --data coco128.yaml --weights yolov5s.pt

能跑
在这里插入图片描述
在这里插入图片描述


(base) C:\Users\Administrator>activate yolo

(yolo) C:\Users\Administrator>cd I:\01ldzx\YOLO\yolov5\yolov5

(yolo) C:\Users\Administrator>I:

(yolo) I:\01ldzx\YOLO\yolov5\yolov5>python train.py --img 640 --batch 2 --epochs
 5 --data coco128.yaml --weights yolov5s.pt
Using torch 1.7.1 CUDA:0 (GeForce GTX 950, 2048MB)

Namespace(adam=False, batch_size=2, bucket='', cache_images=False, cfg='', data=
'coco128.yaml', device='', epochs=5, evolve=False, exist_ok=False, global_rank=-
1, hyp='data/hyp.scratch.yaml', image_weights=False, img_size=[640, 640], local_
rank=-1, log_artifacts=False, log_imgs=16, multi_scale=False, name='exp', noauto
anchor=False, nosave=False, notest=False, project='runs/train', rect=False, resu
me=False, save_dir='runs\\train\\exp12', single_cls=False, sync_bn=False, total_
batch_size=2, weights='yolov5s.pt', workers=1, world_size=1)
Start Tensorboard with "tensorboard --logdir runs/train", view at http://localho
st:6006/
Hyperparameters {'lr0': 0.01, 'lrf': 0.2, 'momentum': 0.937, 'weight_decay': 0.0
005, 'warmup_epochs': 3.0, 'warmup_momentum': 0.8, 'warmup_bias_lr': 0.1, 'box':
 0.05, 'cls': 0.5, 'cls_pw': 1.0, 'obj': 1.0, 'obj_pw': 1.0, 'iou_t': 0.2, 'anch
or_t': 4.0, 'fl_gamma': 0.0, 'hsv_h': 0.015, 'hsv_s': 0.7, 'hsv_v': 0.4, 'degree
s': 0.0, 'translate': 0.1, 'scale': 0.5, 'shear': 0.0, 'perspective': 0.0, 'flip
ud': 0.0, 'fliplr': 0.5, 'mosaic': 1.0, 'mixup': 0.0}

                 from  n    params  module                                  argu
ments
  0                -1  1      3520  models.common.Focus                     [3,
32, 3]
  1                -1  1     18560  models.common.Conv                      [32,
 64, 3, 2]
  2                -1  1     19904  models.common.BottleneckCSP             [64,
 64, 1]
  3                -1  1     73984  models.common.Conv                      [64,
 128, 3, 2]
  4                -1  1    161152  models.common.BottleneckCSP             [128
, 128, 3]
  5                -1  1    295424  models.common.Conv                      [128
, 256, 3, 2]
  6                -1  1    641792  models.common.BottleneckCSP             [256
, 256, 3]
  7                -1  1   1180672  models.common.Conv                      [256
, 512, 3, 2]
  8                -1  1    656896  models.common.SPP                       [512
, 512, [5, 9, 13]]
  9                -1  1   1248768  models.common.BottleneckCSP             [512
, 512, 1, False]
 10                -1  1    131584  models.common.Conv                      [512
, 256, 1, 1]
 11                -1  1         0  torch.nn.modules.upsampling.Upsample    [Non
e, 2, 'nearest']
 12           [-1, 6]  1         0  models.common.Concat                    [1]

 13                -1  1    378624  models.common.BottleneckCSP             [512
, 256, 1, False]
 14                -1  1     33024  models.common.Conv                      [256
, 128, 1, 1]
 15                -1  1         0  torch.nn.modules.upsampling.Upsample    [Non
e, 2, 'nearest']
 16           [-1, 4]  1         0  models.common.Concat                    [1]

 17                -1  1     95104  models.common.BottleneckCSP             [256
, 128, 1, False]
 18                -1  1    147712  models.common.Conv                      [128
, 128, 3, 2]
 19          [-1, 14]  1         0  models.common.Concat                    [1]

 20                -1  1    313088  models.common.BottleneckCSP             [256
, 256, 1, False]
 21                -1  1    590336  models.common.Conv                      [256
, 256, 3, 2]
 22          [-1, 10]  1         0  models.common.Concat                    [1]

 23                -1  1   1248768  models.common.BottleneckCSP             [512
, 512, 1, False]
 24      [17, 20, 23]  1    229245  models.yolo.Detect                      [80,
 [[10, 13, 16, 30, 33, 23], [30, 61, 62, 45, 59, 119], [116, 90, 156, 198, 373,
326]], [128, 256, 512]]
Model Summary: 283 layers, 7468157 parameters, 7468157 gradients, 17.5 GFLOPS

Transferred 370/370 items from yolov5s.pt
Optimizer groups: 62 .bias, 70 conv.weight, 59 other
Scanning '..\coco128\labels\train2017.cache' for images and labels... 128 found
Scanning '..\coco128\labels\train2017.cache' for images and labels... 128 found
Analyzing anchors... anchors/target = 4.26, Best Possible Recall (BPR) = 0.9946
Image sizes 640 train, 640 test
Using 1 dataloader workers
Logging results to runs\train\exp12
Starting training for 5 epochs...

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size

Scanning '..\coco128\labels\train2017.cache' for images and labels... 128 found
       0/4    0.847G   0.04502   0.07511   0.02855    0.1487        19       64
               Class      Images     Targets           P           R      mAP@.
                 all         128         929       0.341       0.781        0.69
       0.455

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size

       1/4    0.847G   0.04517   0.07459    0.0295    0.1493        40       64
               Class      Images     Targets           P           R      mAP@.
                 all         128         929       0.325       0.802       0.703
       0.447

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size

       2/4    0.847G   0.04585   0.07038   0.02843    0.1447        18       64
               Class      Images     Targets           P           R      mAP@.
                 all         128         929       0.322       0.802       0.707
       0.461

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size

       3/4    0.847G    0.0441   0.07255    0.0299    0.1466        14       64
               Class      Images     Targets           P           R      mAP@.
                 all         128         929       0.306       0.802       0.719
       0.462

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size

       4/4    0.847G   0.04388   0.06547   0.02902    0.1384        22       64
               Class      Images     Targets           P           R      mAP@.
                 all         128         929       0.301       0.799       0.723
       0.477
Optimizer stripped from runs\train\exp12\weights\last.pt, 15.2MB
Optimizer stripped from runs\train\exp12\weights\best.pt, 15.2MB
5 epochs completed in 0.060 hours.


  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
这个错误是由于CUDA内存不足导致的。根据引用\[1\]和引用\[2\]的信息,你的GPU总容量为4.00 GiB或10.76 GiB,但已经分配了2.34 GiB或1.82 GiB的内存,剩余的内存不足以分配14.00 MiB的内存。这可能是由于你的模型或数据的规模过大,导致内存不足。你可以尝试减小batch size或者使用更小的模型来减少内存的使用。另外,你还可以尝试设置max_split_size_mb参数来避免内存碎片化。关于内存管理和PYTORCH_CUDA_ALLOC_CONF的更多信息,请参考PyTorch的文档。 此外,根据引用\[3\]的信息,你还可以通过手动杀死占用GPU内存的进程来释放内存。你可以使用kill命令加上进程的PID来终止该进程,例如kill -9 31272。 综上所述,你可以通过减小batch size、使用更小的模型、设置max_split_size_mb参数或手动杀死占用内存的进程来解决CUDA内存不足的问题。 #### 引用[.reference_title] - *1* [已解决yolov5报错RuntimeError: CUDA out of memory. Tried to allocate 14.00 MiB](https://blog.csdn.net/Code_and516/article/details/129798540)[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^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [解决RuntimeError: CUDA out of memory. Tried to allocate 14.00 MiB](https://blog.csdn.net/qq_43733107/article/details/126876755)[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^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

WayHonor-机器视觉

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值