Train DOTA dataset with yolov3

Josh Lin
3 min readJan 10, 2020

--

Most articles teach you to train on VOC or COCO, yes you trained and have good result, yet do you learn ML just to detect such objects everyone can do? Here in this article, I guide you though the steps for training on DOTA dataset — A Large-scale Dataset for Object DeTection in Aerial Images

the official site refered an yolov2 repo, from where I borrowed some code too

here is my yolov3 repo

you can have a quick glance on youtube and see how it works

1. clone the reop

git clone xxxx/dota-yolo
cd dota-yolo

2. download DOTA dataset

download link can be found here

then put them into the cloned repo as following structure

DOTA-yolov3
|
├─dataset
│ ├─train
│ │ ├─images
│ │ └─labelTxt
│ └─val
│ ├─images
│ └─labelTxt

3. prerequisites

you need to have some lib/tool installed

4. split

beacuse the images in dataset are really huge, if you train directly, it likely will overflow your GPU memory, so we split images into small ones, as well as corresponding labels

python3 data_transform/split.py

for more about spliting, you can refer here

5. transform label

the labels are not in yolo format yet, so we need to convert them to yolo format

mkdir dataset/trainsplit/labels
mkdir dataset/valsplit/labels
python3 data_transform/YOLO_Transform.py

most transform code I borrowed from dota yolov2 repo

you can check the transformed labels with this command

# check labels
# cd dataset/trainsplit/labels
# awk -F" " '{col[$1]++} END {for (i in col) print i, col[i]}' *.txt

6. generate train.txt & val.txt

when we train, we need train set to train the weights, and validate set to check how accurate the weights are now

ls -1d $PWD/dataset/trainsplit/images/* > cfg/train.txt
ls -1d $PWD/dataset/valsplit/images/* > cfg/val.txt

7. train

cd cfg
mkdir backup

for yolov3-tiny

# yolo-tiny
darknet detector train dota.data dota-yolov3-tiny.cfg

for yolov3

# or yolov3-416
darknet detector train dota.data dota-yolov3-416.cfg

and more params, you can refer darknet usage

# more gpus
darknet detector train dota.data dota-yolov3-tiny.cfg -gpus 0,1,2

# resume from unexpected stop
darknet detector train dota.data dota-yolov3-tiny.cfg backup/dota-yolov3-tiny.backup

you may not use 416X416 input or modify any other config, you can refer how the cfg file configed here

8. predict

# tiny
python test.py --image test.png --config cfg/dota-yolov3-tiny.cfg --weights cfg/backup/dota-yolov3-tiny_final.weights --classes cfg/dota.names

# or 416
python test.py --image test.png --config cfg/dota-yolov3-416.cfg --weights cfg/backup/dota-yolov3-416_final.weights --classes cfg/dota.names

Here I prepared test code with opencv for easy set up, you can use darknet bindings for better performance

9. pretrained weights

you can download my pretrained weights here

if you missed something, you can follow youtube steps or leave a comment, hope this guide can help you!

--

--