Environment Setup (It depends.)

  • Python 3.6.5
  • Keras 2.2.2
  • tensorflow 1.4.0

Clone from the github

   
      git clone https://github.com/qqwweee/keras-yolo3
    

Download the weights from the darket official website

   
      wget https://pjreddie.com/media/files/yolov3.weights
    

Convert the weights file from Darket to Keras

1
python convert.py yolov3.cfg yolov3.weights model_data/yolo.h5

Prepare your own dataset as VOC format, and remember to split the dataset in to train and test in the ImageSets/Main/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import os,random

# read the filenames from a file
dirname = './Annotations'
files = [f[:-4] for f in os.listdir(dirname) if f[-4:].lower() == '.xml']

# random divide
trainval = random.sample(files, len(files)//2)
test = [f for f in files if f not in trainval]

# random divide
train = random.sample(trainval, len(trainval)//2)
val = [f for f in trainval if f not in train]

# save to txt file
def list2txt(arr, fname):
with open(fname+'.txt', 'w') as f:
for a in arr:
f.write(a+'\n')

list2txt(trainval, 'trainval')
list2txt(test, 'test')
list2txt(train, 'train')
list2txt(val, 'val')

Generate your own annotation file and class names file for keras

1
python voc_annotation.py
  • Just like this

Modify your voc_classes.txt file

  • It’s in themodel_data/voc_classes.txt

Start training

1
python train.py

Test

  • After training, Use the final model to test your new photos, modify the yolo.py on line23, change it to the new trained model path, then
    1
    python yolo_video.py --image