파이썬/yolo

[ yolov7 ] Train , Detect , Test

code094 2023. 1. 6. 13:38

https://github.com/WongKinYiu/yolov7

 

GitHub - WongKinYiu/yolov7: Implementation of paper - YOLOv7: Trainable bag-of-freebies sets new state-of-the-art for real-time

Implementation of paper - YOLOv7: Trainable bag-of-freebies sets new state-of-the-art for real-time object detectors - GitHub - WongKinYiu/yolov7: Implementation of paper - YOLOv7: Trainable bag-of...

github.com

train 

1. yolov7 도커 이미지 다운받음

sudo docker pull nvcr.io/nvidia/pytorch:21.08-py3

2. 도커 컨테이너 생성해줌 

sudo nvidia-docker run --name yolov7train -it -v /home/code094:/home -v /home/code094/python:/yolo --shm-size=64g nvcr.io/nvidia/pytorch:21.08-py3

3. 도커 컨테이너 안에서 /home 폴더 권한 chmod +x 이용해서 바꿔줌 

4. 순서대로 업데이트 및 설치하고 

apt update 
apt install -y zip htop screen libgl1-mesa-glx

pip install seaborn thop

cd /yolov7

5. yolov7 다운받음 

git clone https://github.com/WongKinYiu/yolov7.git

6. 데이터를 준비함 train , val 8 : 2 로 데이터 넣었음 

7. 데이터 학습 시킴 

    여기선 원래 있는 weight 파일 사용했고 yaml 파일은 원하는 클래스만 넣었음 

    GPU 4 개 사용하고 batch 사이즈 조절하면서 학습함 

python -m torch.distributed.launch --nproc_per_node 4 train.py --workers 8 --device 0,1,2,3 --batch-size 64 --data /yolo/dataset.yaml --img 640 640 --cfg cfg/training/yolov7.yaml --weights 'yolov7_training.pt' --name yolov7-custom --hyp data/hyp.scratch.custom.yaml

 

detect ( 학습된 모델로 예측 )

train 결과로 만들어진 best.pt 란 weight 파일로 detect 시킴

그럼 이미지에 bbox 그려진거 확인할 수 있음 (save-txt default 를 true로 해둠) 

python detect.py --weight /yolo/best.pt--conf 0.7 --img-size 640 --source /yolo/dataset

test 

python test.py --data data/coco.yaml --img 640 --batch 32 --conf 0.001 --iou 0.65 --device 0 --weights best.pt --name yolov7_640_val