synml / yolov3-pytorch

A Simple PyTorch Implementation of YOLOv3
MIT License
9 stars 2 forks source link

RuntimeError: CUDA error: device-side assert triggered #3

Open 2hyes opened 3 years ago

2hyes commented 3 years ago

1개의 class(사람)만을 detect하려고 커스텀 데이터셋을 학습 시키고자 합니다. data/.names, config/.data, data/train.txt, data/val.txt모두 수정했고 train.py의 argument부분도 모두 수정했습니다.

pytorch/aten/src/ATen/native/cuda/IndexKernel.cu:84: operator(): block: [0,0,0], thread: [67,0,0] Assertion `index >= -sizes[i] && index < sizes[i] && "index out of bounds"` failed.s: 15.266020 
/pytorch/aten/src/ATen/native/cuda/IndexKernel.cu:84: operator(): block: [0,0,0], thread: [69,0,0] Assertion `index >= -sizes[i] && index < sizes[i] && "index out of bounds"` failed.
/pytorch/aten/src/ATen/native/cuda/IndexKernel.cu:84: operator(): block: [0,0,0], thread: [41,0,0] Assertion `index >= -sizes[i] && index < sizes[i] && "index out of bounds"` failed.
/pytorch/aten/src/ATen/native/cuda/IndexKernel.cu:84: operator(): block: [0,0,0], thread: [43,0,0] Assertion `index >= -sizes[i] && index < sizes[i] && "index out of bounds"` failed.
/pytorch/aten/src/ATen/native/cuda/IndexKernel.cu:84: operator(): block: [0,0,0], thread: [44,0,0] Assertion `index >= -sizes[i] && index < sizes[i] && "index out of bounds"` failed.
/pytorch/aten/src/ATen/native/cuda/IndexKernel.cu:84: operator(): block: [0,0,0], thread: [45,0,0] Assertion `index >= -sizes[i] && index < sizes[i] && "index out of bounds"` failed.

Traceback (most recent call last):                                                                                                                                                
  File "train.py", line 78, in <module>
    loss, outputs = model(images, targets)
  File "/home/user/pyenv/versions/temp/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/home/useryolov3-pytorch/model/yolov3.py", line 167, in forward
    yolo_output3, layer_loss = self.yolo_layer3(scale3, targets)
  File "/home/user/.pyenv/versions/temp/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/home/useryolov3-pytorch/model/yolov3.py", line 68, in forward
    iou_scores, class_mask, obj_mask, no_obj_mask, tx, ty, tw, th, tcls, tconf = utils.utils.build_targets(
  File "/home/user/yolov3-pytorch/utils/utils.py", line 335, in build_targets
    noobj_mask[b[i], anchor_ious > ignore_thres, gj[i], gi[i]] = 0
RuntimeError: CUDA error: device-side assert triggered

utils.py의 build_targets 함수에서 이런 오류가 나고있습니다. coco 데이터셋으로는 나지않았던 오류라, 혹시 같은 오류의 경험이 있으실까하여 올려봅니다!

synml commented 3 years ago

안녕하세요. 우선 제 리포지토리를 사용해주셔서 감사합니다. 이 문제는 train할 때, groundtruth를 불러와 넣어주면서 발생하는 오류입니다. 제 예상으로는 입출력 shape 불일치, class 번호가 0 ~ 1이 아님 등으로 생각합니다. 저도 버그를 살펴보겠지만, 도움이 되실 자료를 올려드립니다. https://ndb796.tistory.com/509 https://brstar96.github.io/shoveling/device_error_summary/

사실 이 코드는 VOC, COCO 데이터셋을 기반으로 작성되어 커스텀 데이터셋은 생각해보지 않았는데, 한번 다시 살펴봐야겠네요. 감사합니다.

synml commented 3 years ago

제가 예전에 yolov3 코드를 작성할 때 참고했던 리포지토리가 있습니다. https://github.com/ultralytics/yolov3 코드 완성도가 높지만 사용법이 살짝 더 어렵습니다. 커스텀 데이터셋을 사용하신다면 이 리포지토리도 큰 도움이 되실거라 생각해요! https://github.com/ultralytics/yolov3/wiki/Train-Custom-Data

2hyes commented 3 years ago

답변감사합니다!

검색해보면서 찾은 정보인데 도움이 될까하여 남깁니다! https://github.com/eriklindernoren/PyTorch-YOLOv3/issues/157

저 + 같은 이슈를 가지신 분들의 많은 경우, valid한 박스 혹은 label정보를 갖고있지않았어서 생기는 에러인 것 같습니다. 해당 링크 중간즈음에 남겨주신 분처럼

b, target_labels = target[:, :2].long().t()
gx, gy = gxy.t()
gw, gh = gwh.t()
gi, gj = gxy.long().t()
########## TODO(arthur77wang):
gi[gi < 0] = 0
gj[gj < 0] = 0
gi[gi > nG - 1] = nG - 1
gj[gj > nG - 1] = nG - 1
###################
# Set masks
obj_mask[b, best_n, gj, gi] = 1
noobj_mask[b, best_n, gj, gi] = 0

코드를 추가하면 에러가 해결됩니다. 다만, 에러를 잡는 용도라서 학습에 문제가 생길 수 있을 것 같다는 생각이 들어, bbox valid 코드를 추가하는 것을 고려하고있습니다.