YOLOv1부터 YOLOv3까지 Josept Redmon이 개발을 했다. 하지만 YOLOv3 개발 이후 computer vision이 자신이 생각한 분야와는 다르게 군사적 목적으로 사용되는것이 싫어 이후 개발을 포기한다고 했다.
이후 AlexeyBochkousky가 YOLOv4 개발을 진행 했다.
하지만 custom dataset으로 train하는 방법은 YOLOv3와 차이가 없다. 따라서 많은 설명은 하지 않도록 하겠다.
환경은 우분투 20.04 LTS 에서 진행 하도록 하겠다. 사전에 설치해야할 항목들은
1. Nvidia-driver
2. CUDA, CUDNN
3. OpenCV
4. Darknet
YOLOv3와 동일하게 준비가 되어 있어야 한다.
custom dataset은 YOLO_mark(다른 annotation tool)을 사용해 학습할 이미지, txt파일(YOLO_format)을 준비한다.
YOLOv4도 아래의 사진과 같이 5개의 파일이 준비되어 있어야 한다.
준비해야할 부분을 하나씩 보도록 하겠다.
1. img 폴더
학습 이미지 와 annotation 파일은 같은 폴더 내에 있어야 한다. 이때 사진 과 annotation의 파일명은 같아야 한다.
2. custom.data
YOLOv3와 다른 부분은 없다. 파일의 경로 classes의 갯수를 잘 적어주면 된다.
3.custom.names
class의 이름이 저장되어 있는 파일이다.
4. train.txt , valid.txt
훈련을 하기위해 train, validation의 이미지의 경로가 저장되어 있는 파일
5. yolov4.cfg
YOLOv3와 구성파일의 모습과 비슷 하다.
각 parameter의 설명 및 내용은 'YOLOv3 custom train' 글을 참고하면 좋을듯 하다.
중요하게 바꿔야 할 부분은 batch size, subdivisions 이라 생각한다.
추가로 yolo를 검색해서 나오는 3 부분을 수정해줘야 한다.
classes = class 갯수 ,filters = (class 개수 + 5) *3, anchors
6. yolov4.conv.137
darknet에서 제공하는 pretrain 모델을 이용하면 좀 더 빠르고 정확한 학습을 진행할 수 있다. pretrained된 모델을 아래의 코드를 입력해 다운로드 받는다.
$ wget https://github.com/AlexeyAB/darknet/releases/download/darknet_yolo_v3_optimal/yolov4.conv.137
이제 YOLOV4를 custom dataset을 이용해 학습을 할 준비가 되었다.
아래의 명령을 입력해 학습을 시작한다.
$ ./darknet detector train custom_yolov4/custom.data custom_yolov4/yolov4.cfg custom_yolov4/yolov4.conv.137 -map | tee backup/train.log
학습이 종료되면 다음과 같이 그래프가 저장이 되어 학습결과를 확인할수 있다.
훈련 결과를 확인 하기 위해 다음과 같이 입력하면 훈련결과를 확인할수 있다.
$ ./darknet detector test custom_yolov4/custom.data custom_yolov4/yolov4.cfg backup/yolov4_best.weights 사진.jpg
$ ./darknet detector demo custom_yolov4/custom.data custom_yolov4/yolov4.cfg backup/yolov4_best.weights -ext_output 동영상.mp4
$ ./darknet detector demo custom_yolov4/custom.data custom_yolov4/yolov4.cfg backup/yolov4_best.weights -c 0 (웹캠)
Reference
https://github.com/AlexeyAB/darknet
https://kumoh-irl.tistory.com/42
정확한 정보 전달보단 공부 겸 기록에 초점을 둔 글입니다. 틀린 내용이 있을 수 있습니다.
틀린 내용이나 다른 문제가 있으면 댓글 남겨주시거나 또는 이메일로 보내주시면
감사하겠습니다.
'Object Detection > YOLO' 카테고리의 다른 글
YOLOv6 custom Train (0) | 2024.01.29 |
---|---|
YOLOv5 custom Train (0) | 2024.01.28 |
YOLOv3 custom Train (0) | 2024.01.25 |
[Ubuntu 20.04 LTS] Darknet 설치 (0) | 2024.01.24 |
YOLO_mark 사용법 (0) | 2024.01.19 |