How to train CenterNet with your own VOC dataset

Kevin Lee·2020년 7월 22일
0

스트라드비젼 인턴

목록 보기
12/12

Convert VOC to COCO

Convert VOC xml annotations to COCO json annotations using voc2coco

voc2coco changes xml annotations to coco json format.

Run script

python voc2coco.py --ann_dir [Annotation folder] --ann_ids [ImageSets]/[txt file] --labels [label.txt] [labelid.txt] --output [outputfile.json] --ext xml

Input as arguments

  • --ann_dir : VOC Annotation file의 파일 경로
  • --ann_id : ImageSet의 txt 파일의 파일 경로 - all.txt는 train, validation 또는 test dataset으로 나눌때 쓴다.
  • --labels : 카테고리의 이름을 담은 label.txt 그리고 카테고리의 id를 담은 labelid.txt
  • --output : 아웃풋 경로

Original voc2coco에서 바뀐거는 image_id를 정하는 방법과 label id를 자동생성하는것이 아닌 사용자가 직접 정할 수 있게 만든거랑 자잘한 변수 타입 issue들을 고친 부분이다.


Setting up the data

If you are not going to split the dataset you can skip this part

Getting jpg files in JPEGImage using txt files in ImageSet. This is for splitting data to different datasets or checking if all images actually exist.

First add the text .jpg at the end of each line

sed 's/$/.jpg/ [source.txt] > [dest.txt]

If you open the new txt file, you will see ^M in every filename. To remove ^M type sed -i 's/[Ctrl+v then Ctrl+M]//g' [dest.txt]

Warning

Do NOT simply type ^M character in bash command use the exact command stated above.

To move or copy the files use this command:

for file in $(cat ~/Desktop/files.txt); do mv "$file" ~/newfolder; done

You can also use this to mv big files.


Configure CenterNet

  • Change the data_dir and categories in config/CenterNet-52 or 104.json
  • In db/coco.py change self._cat_ids to the category IDs you have used in labelids.txt to change VOC to COCO
  • Change self_configs["categories"] and num_classes under self_model['bbox_head'] in db/detection.py
  • Lastly change out_dim under class model(kp) in models/CenterNet-104 or 52.py

Now train!

profile
🧠🦾❤ https://github.com/to2915ny

0개의 댓글