A Keras implementation of YOLOv3 (Tensorflow backend) inspired by allanzelener/YAD2K. This fork is a continuation of qqwweee/keras-yolo3 with some CI and bug fixing since its parent become inactive...
For package installation use of the following commands
pip install git+https://github.com/Borda/keras-yolo3.git
pip install https://github.com/Borda/keras-yolo3/archive/master.zip
or clone/download repository locally and run python setup.py install
For more model and configuration please see YOLO website and darknet repository.
- Download YOLOv3 weights from YOLO website.
alternatively you can download light version
wget -O ./model_data/yolo3.weights \ https://pjreddie.com/media/files/yolov3.weights \ --progress=bar:force:noscroll
yolov3-tiny.weights
- Convert the Darknet YOLO model to a Keras model.
python3 scripts/convert_weights.py \ --config_path ./model_data/yolo.cfg \ --weights_path ./model_data/yolo.weights \ --output_path ./model_data/yolo.h5
- Run YOLO detection.
For Full YOLOv3, just do in a similar way, just specify model path and anchor path with
python3 scripts/detection.py \ --path_weights ./model_data/yolo.h5 \ --path_anchors ./model_data/yolo_anchors.csv \ --path_classes ./model_data/coco_classes.txt \ --path_output ./results \ --path_image ./model_data/bike-car-dog.jpg \ --path_video person.mp4
--path_weights <model_file>
and--path_anchors <anchor_file>
. - MultiGPU usage: use
--nb_gpu N
to use N GPUs. It is passed to the Keras multi_gpu_model().
For training you can use VOC dataset, COCO datset or your own...
- Generate your own annotation file and class names file.
- One row for one image;
- Row format:
image_file_path box1 box2 ... boxN
; - Box format:
x_min,y_min,x_max,y_max,class_id
(no space). - Run one of following scrips for dataset conversion
scripts/annotation_voc.py
scripts/annotation_coco.py
scripts/annotation_csv.py
Here is an example:
path/to/img1.jpg 50,100,150,200,0 30,50,200,120,3 path/to/img2.jpg 120,300,250,600,2 ...
- Make sure you have run
python scripts/convert_weights.py <...>
. The filemodel_data/yolo_weights.h5
is used to load pre-trained weights. - Modify training.py and start training.
python training.py
. Use your trained weights or checkpoint weights with command line option--model model_file
when usingyolo_interactive.py
. Remember to modify class path or anchor path, with--classes class_file
and--anchors anchor_file
.
If you want to use original pre-trained weights for YOLOv3:
wget https://pjreddie.com/media/files/darknet53.conv.74
- rename it as
darknet53.weights
python convert.py -w darknet53.cfg darknet53.weights model_data/darknet53_weights.h5
- use
model_data/darknet53_weights.h5
intraining.py
- The test environment is Python 3.x ; Keras 2.2.0 ; tensorflow 1.14.0
- Default anchors are used. If you use your own anchors, probably some changes are needed.
- The inference result is not totally the same as Darknet but the difference is small.
- Always load pretrained weights and freeze layers in the first stage of training. Or try Darknet training. It's OK if there is a mismatch warning.
- The training strategy is for reference only. Adjust it according to your dataset and your goal. and add further strategy if needed.
- For speeding up the training process with frozen layers train_bottleneck.py can be used. It will compute the bottleneck features of the frozen model first and then only trains the last layers. This makes training on CPU possible in a reasonable time. See this post for more information on bottleneck features.
- Failing while run multi-GPU training, think about porting to TF 2.0.