관리 메뉴

ComputerVision Jack

Darknet to Caffe 본문

Computer Vision/Model Convert

Darknet to Caffe

JackYoon 2021. 6. 8. 21:48
반응형

오늘은 어제에 이어서 darknet model을 caffe model로 converting 하는 방법을 이야기하겠습니다.

darknet framewrok를 사용하는 대표적인 yolo로 진행해보려고 합니다.

 

하지만 caffe model로 converting 하려면 yolo에 필요한 layer들을 따로 추가해야하는 상황이 발생합니다.

그래서 제가 찾은 public code를 소개합니다.

https://github.com/ChenYingpeng/darknet2caffe

 

ChenYingpeng/darknet2caffe

Convert darknet weights to caffemodel. Contribute to ChenYingpeng/darknet2caffe development by creating an account on GitHub.

github.com

해당 github code를 이용하시면 caffe layer를 추가할 수 있고 converting을 진행할 수 있습니다.

gitclone 진행 후

darknet framework는 2가지의 input이 필요합니다.

  • cfg 파일 : model structure 담고 있는 파일
  • weights 파일 : model의 가중치를 담고있는 파일

2가지 파일을 darknet2caffe.py의 input으로 넣어야합니다. 그렇게 python darknet2caffe.py 파일을 실행하면 converting이 진행되는 것을 확인할 수 있습니다.

converting 완료

오히려 keras 모델 변환보다 쉬운 느낌이 있습니다.

 

시간이 좀더 남은 관계로 darknet framework 이야기화 학습을 좀 살펴보겠습니다.

우선 yolov1 yolov2의 경우 조셉님이 개발하셨습니다. https://pjreddie.com/darknet/yolo/

 

YOLO: Real-Time Object Detection

YOLO: Real-Time Object Detection You only look once (YOLO) is a state-of-the-art, real-time object detection system. On a Pascal Titan X it processes images at 30 FPS and has a mAP of 57.9% on COCO test-dev. Comparison to Other Detectors YOLOv3 is extremel

pjreddie.com

해당 사이트를 들어가시면 yolo와 관련된 cfg 파일과 weights 파일을 다운로드 받으실 수 있습니다.

이후 yolov3 경우 AlexeyAB님께서 진행하였습니다. 해당 관련 사이트는 하단에 첨부하겠습니다.

GitHub - pjreddie/darknet: Convolutional Neural Networks

 

pjreddie/darknet

Convolutional Neural Networks. Contribute to pjreddie/darknet development by creating an account on GitHub.

github.com

상단의 링크를 통해 cfg와 weights 파일을 받고 하단의 github에서 darknet 학습을 진행할 수 있습니다.

yolo는 k-means를 바탕으로 anchor를 계산합니다. 따라서 data가 준비되었다면

./darknet detector calc_anchors ./coco.data -num_of_clusters 9 - width 416 -height 416

명령어를 통해 anchor를 계산할 수 있습니다.

anchor calc

./darknet detector train ./coco.data ./yolov3-tiny.cfg ./yolov3-tiny.conv11 -map -gpus 0

그런다음 해당 명령어를 통해 학습을 실행하면됩니다.

converting 후 시간이 남은 관계로 짧게 darknet framework 관련하여 포스팅을 하였는데, 다음번에 darknet을 통해 모델을 학습하는 방법에 대해 정리해서 남기겠습니다. 감사합니다.

반응형

'Computer Vision > Model Convert' 카테고리의 다른 글

Keras to TFlite  (0) 2021.06.15
Keras to Caffe  (0) 2021.06.07
Comments