상세 컨텐츠

본문 제목

Yolov7 based Pose Estimation

Machine Learning

by 땅콩또복 2022. 9. 19. 22:33

본문

Pose estimation (from https://pose.mpi-inf.mpg.de/)

https://github.com/WongKinYiu/yolov7/tree/pose

Pose estimation은 다음 링크를 사용한다.

 

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

 

다른 task들과 같은 backbone을 쓰면서 동시에 popular task 중에 하나인 pose estimation을 마지막을 진행해보고자 한다.

 

다행히도 Yolov7 repo.에서 크게 바꾸지 않아도 무난히 실행 된다.

 

Keypoint dataset preparation

(새로 coco_kpts 폴더를 생성하고, 기존 coco 폴더에서 images & annotations 폴더를 copy 해서 사용)

 

Training on COCO

  • --device: 사용할 GPU numbers
  • --batch-size: batch size
  • --data: 데이터셋 관련 config (e.g. 경로 (train/val/test), #classes, labels)
  • --img: image size
  • --cfg: Architecture 정보 (backbone + head)
  • --weights: Pretrained weight (training 과정에서는 (resume이 아니라면) 필요 없으니 공란)
  • --name: project name
  • --hyp: hyperparameter config (e.g. learning rate, momentum 등)
# Single GPU 경우
python train.py --data data/coco_kpts.yaml --cfg cfg/yolov7-w6-pose.yaml --weights '' --batch-size 128 --img 960 --kpt-label --device 0,1,2,3 --name yolov7-w6-pose --hyp data/hyp.pose.yaml

# Multiple GPU 경우 (이거 아직 안됨)
python -m torch.distributed.launch --nproc_per_node 8 --master_port 9527 train.py --data data/coco_kpts.yaml --cfg cfg/yolov7-w6-pose.yaml --weights '' --batch-size 128 --img 960 --kpt-label --sync-bn --device 0,1,2,3 --name yolov7-w6-pose --hyp data/hyp.pose.yaml

Trouble shooting during training

  • Out of memory: batch size를 줄이자
  • Float > long issue: utils/loss.py에서 gain = ... 부분 마지막에 .long() 추가

실험이 끝나고 model & config 은 runs/train/yolov7_w6_pose/ 에 저장된다

  • weights/best.pt : Final (best) model
  • hyp.yaml: 사용했던 hyperparameters (e.g. learning rate, momentum 등)
  • opt.yaml: 코드 실행했을 때 사용했던 configuration 정보 (--worker, --batch-size, --name 등)

Inference on Image

python detect.py --weights yolov7-w6-pose.pt --kpt-label --source your_image.jpg

Inference on Video

python detect.py --weights yolov7-w6-pose.pt --kpt-label --source your_video.mp4

Arguments

주로 사용되는 argument는 다음과 같다

1. weights: pretrained model PATH
2. source: dataset PATH
3. img-size: image size during inference step
4. conf-thres: object confidence threshold (Yolo loss function 참고)
5. iou-threshold: IOU threshold (Yolo loss function 참고)
6. device: 사용할 device (e.g. 0 or 0,1,2,3 or cpu)
7. view-img: display results
8. save-txt: 결과 txt로 저장
9. save-conf: confidence socre 저장
10. nosave: 결과 저장 안함
11. classes: class 표시할지 여부 (e.g. --class 0, or --class 0 2 3)
12. project: project 저장할 폴더 PATH
13. name: project name (뒤에 숫자가 붙는 형식: e.g. exp1, exp2, ...)
14. nbbox: hide bounding boxes
15. kpt-label: key-point label (pose estimation에서는 반드시 사용해야 할 hyperparameter)

Results

 

Original dataset: https://www.kaggle.com/datasets/nizdarlaila/videos

 

Conclusion

 

생각보다 Inference는 너무 쉬워서 쉽게 따라할 수 있을 것 같다.

관련글 더보기

댓글 영역