learnopencv.com/training-yolov3-deep-learning-based-custom-object-detector/ : 간략요약
<snowman detector>- 구글 코랩에서 수행.
소스 다운로드
!git clone https://github.com/spmallick/learnopencv.git
%cd learnopencv/YOLOv3-Training-Snowman-Detector
1. Dataset
1.1 Download data [approx 1 hour]
!pip3 install awscli #awscli설치/ 에러날경우 무시해도 됨.
openImages files을 다운받기 위한 작업:
!wget https://storage.googleapis.com/openimages/2018_04/class-descriptions-boxable.csv
!wget https://storage.googleapis.com/openimages/2018_04/train/train-annotations-bbox.csv
!python3 getDataFromOpenImages_snowman.py
images 는 JPEGImages folder로, label files은 labels folder로 다운로드 된다.
1.3 Train-test split
!python3 splitTrainAndTest.py /full/path/to/snowman/JPEGImages/
위의 /full/path/to/snowman/JPEGImages/ 는 JPEGImages folder의 full path로 바꾸어 써주면됨.
train(90%), test(10%)로 나누고, snowman_train.txt, snowman_test.txt 2개의 파일이 생성된다.
2. Darknet
2.1 Download and build Darknet
%cd ~
!git clone https://github.com/pjreddie/darknet
%cd darknet
2.2 Modify code to save model files regularly
~/darknet/examples/detector.c 를 수정한다.(138번째줄)
if(i%10000==0 || (i < 1000 && i%100 == 0)){
==>
if(i%1000==0 || (i < 2000 && i%200 == 0)){
추가로, GPU쓰는 경우, Makefile을 다음처럼 set한다.
GPU=1
CUDNN=1
최근 뭐가 바뀌었는지 make시 에러가 나서, Makefile 7번째줄, ARCH= -gencode arch=compute_30,code=sm_30 \ 부분부터 문장끝까지 주석처리하고, # This is what I use, uncomment if you know your arch and want to specify 밑의 행을 주석을 풀고 하면됨.
그리고나서, 다시 !make 한다.
3. Data Annotation
labels folder에 있는 파일들은 하나의 label file에서 각 row entry는 the image에서 single bounding box를 나타내며, 다음정보를 담고있다.
object-class-id는 the object의 클래스를 나타내는 integer다.(0부터시작)
center-x 와 center-y 는 the center of the bounding box의 x , y 좌표다.(이미지 사이즈로 나눠서 0~1로 노멀라이즈됐다)
width , height 는 the bounding box의 width , height다.(역시, 이미지 사이즈로 나눠서 normalized됨)
4. Download Pre-trained model
%cd ~/darknet
!wget https://pjreddie.com/media/files/darknet53.conv.74 -O ~/darknet/darknet53.conv.74
5. Data file
제공된 darknet.data를, 모두 실제경로로 바꿔 쓴다.
backup parameter: 실제하는 폴더의 경로로, intermediate weights files을 저장한다.
6. YOLOv3 configuration parameters
darknet-yolov3.cfg 세팅.
6.1 Batch hyper-parameter in YOLOv3
batch parameter: 훈련중, batch size를 의미.
6.2 Subdivisions configuration parameter in YOLOv3
subdivisions: GPU에서 한번에 실행될, 배치사이즈의 일정부분.
GPU는 batch/subdivision 개의 images 를 한번에 처리한다.
6.3 Width, Height, Channels
input training images 가 학습되기전에 width x height 로 리사이즈된다.
6.4 Momentum and Decay
weight update가 모든 이미지를 대상으로 하지않기때문에, 많이 변동을 거듭할수 있어서, 큰 변동을 막기위해 momentum사용.
decay 는 오버피트를 막기위해 사용.
6.5 Learning Rate, Steps, Scales, Burn In (warm-up)
매우처음시간에 짧은 시간동안 낮은 learning rate를 갖으면 학습속도가 빨라지는데 이를 조절하는것을 Burn In 또는, warm-up이라 한다.
6.6 Data augmentation
6.7 Number of iterations
max_batches로 n-classes object detector인경우,최소 2000*n batches로 학습하도록 추천된다.
7. Training YOLOv3
%cd ~/darknet
!./darknet detector train /path/to/snowman/darknet.data /path/to/snowman/darknet-yolov3.cfg ./darknet53.conv.74 > /path/to/snowman/train.log
7.1 When do we stop the training?
오차그래프 그리기: python3 plotTrainLoss.py /full/path/to/train.log
mAP를 계산하기위해선, AlexAB‘s fork of darknet 를 사용해라.
8. Testing the model
object_detection_yolo.py파일에서, modelConfiguration, modelWeights 에 대해 올바른 경로를 쓰고, 또는 image or video로 아래와 같이 테스트가능.(video파일은 --video=파일명)
python3 object_detection_yolo.py --image=snowmanImage.jpg
'머신러닝_딥러닝' 카테고리의 다른 글
object detection - 욜로v3 with OpenCV(inference test) 설명 (0) | 2021.06.03 |
---|---|
결정트리 학습된 모델 시각화: Graphviz Visualize (0) | 2021.01.26 |
머신러닝, 딥러닝 Mnist 학습된 모델 테스트 GUI소스 (0) | 2021.01.26 |