欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Yolov3训练时报错RuntimeError: CUDA error: device-side assert triggered

程序员文章站 2024-03-30 22:44:03
报错Traceback (most recent call last): File "train.py", line 122, in loss, outputs = model(imgs, targets) File "/home/pinery/anaconda3/envs/tf3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 532, in __call__ result...

报错

Traceback (most recent call last):
  File "train.py", line 122, in <module>
    loss, outputs = model(imgs, targets)
  File "/home/pinery/anaconda3/envs/tf3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 532, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/pinery/code/YOLO/PyTorch-YOLOv3/models.py", line 263, in forward
    x, layer_loss = module[0](x, targets, img_dim)
  File "/home/pinery/anaconda3/envs/tf3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 532, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/pinery/code/YOLO/PyTorch-YOLOv3/models.py", line 188, in forward
    ignore_thres=self.ignore_thres,
  File "/home/pinery/code/YOLO/PyTorch-YOLOv3/utils/utils.py", line 319, in build_targets
    noobj_mask[b[i], anchor_ious > ignore_thres, gj[i], gi[i]] = 0
RuntimeError: CUDA error: device-side assert triggered

解决方法

Yolov3训练时报错RuntimeError: CUDA error: device-side assert triggered
原因:真实边界框越界,需要调整一下。
1.打开utils/utils.py
2.增添代码如下,放置在上图位置中

gi[gi < 0] = 0
gj[gj < 0] = 0
gi[gi > nG - 1] = nG - 1
gj[gj > nG - 1] = nG - 1

参考资料:https://github.com/eriklindernoren/PyTorch-YOLOv3/issues/157

本文地址:https://blog.csdn.net/qq_35407318/article/details/110938466