if results[0].masks is not None:
combined_mask = np.zeros(frame.shape[:2], dtype=np.uint8)
clss = results[0].boxes.cls.cpu().tolist()
masks = results[0].masks.xy
for mask, cls in zip(masks, clss):
mask_color = colors(int(cls), True)
# random_color = tuple(np.random.randint(0, 256, 3).tolist())
# mask_color = (int(random_color[0]), int(random_color[1]), int(random_color[2]))
cv2.polylines(frame, [np.int32([mask])], isClosed=True, color=mask_color, thickness=3)
cv2.fillPoly(frame, [np.int32([mask])], color=mask_color)
YOLO를 돌리다가 갑자기 죽어버리더니 Segmentation fault (core dumped) 라는 에러가 발생했다.
Segmentation fault (core dumped)" 에러는 프로그램이 잘못된 메모리 접근을 시도할 때 발생하는 오류입니다. 이는 주로 UNIX 기반 운영체제에서 발생하며, 프로그램이 할당받지 않은 메모리 주소에 접근하거나, 허용되지 않은 방식으로 메모리를 읽거나 쓰려고 할 때 운영체제에 의해 발생합니다.
Ultralytics Github에 들어가니, 대부분 해결책은 아래와 같았다.
1. Linux 재설치
2. pytorch 삭제 후 최신 버전 재설치, YOLO 재설치
Linux는 건드리기도 싫었고, 동일한 코드를 클라우드 환경에서도, 내 로컬 PC에서도 발생하는 것로 보아 환경이나 Linux 문제는 아닌듯 했다. 특히, 클라우드에서 발생하는 것은 말이 안 되었다. 결국 내가 작성한 코드 문제.
if results[0].masks is not None:
combined_mask = np.zeros(frame.shape[:2], dtype=np.uint8)
clss = results[0].boxes.cls.cpu().tolist()
masks = results[0].masks.xy
for mask, cls in zip(masks, clss):
mask_color = colors(int(cls), True)
# random_color = tuple(np.random.randint(0, 256, 3).tolist())
# mask_color = (int(random_color[0]), int(random_color[1]), int(random_color[2]))
if len(mask) > 0:
cv2.polylines(frame, [np.int32([mask])], isClosed=True, color=mask_color, thickness=3)
cv2.fillPoly(frame, [np.int32([mask])], color=mask_color)
여기서 발생한 것은 이미지 mask에서 cv2.polylines와 cv2.fillPolys에서 전달되는 mask에 되한 문제였다. 코드 중에서 [np.int32([mask])]로 각 polyline 좌표를 보내주는데 이 부분에 좌표가 하나도 없는 경우 발생했다.
그래서 아래와 같이 길이 조건만 넣어주면 Segmentation fault 에러는 해결된다.
728x90
'공부하는삶 > CV' 카테고리의 다른 글
[TIL] Emerging Properties in Self-Supervised Vision Transformers (0) | 2025.02.04 |
---|---|
[TIL] CVAT 설치하기 (0) | 2023.12.22 |
[TIL] 영상을 탐지한 후, BBOX에 한글을 출력하기 (0) | 2023.12.06 |
pycocotools 설치 에러 (0) | 2023.08.29 |
OpenCV 저장 영상 웹 재생시 코덱 문제 (0) | 2023.08.29 |
You Only Look Once: Unified, Real-Time Object Detection (0) | 2023.08.29 |