yolov3-pytorch
yolov3-pytorch copied to clipboard
A pytorch implementation of yolov3
yolov3-pytorch
A pytorch implementation of yolov3
This code is based on the official code of YOLOv3, as well as a pytorch implementation
YOLOv3_PyTorch.One of the goals of this code is training to get the result close
to the official one.So I improve the calculation of loss functions in yolo_loss.py and add lots of data augmentation such as random cropping,
flip horizontal, and multi-scale training in data_transform.py.I think I achieve a good result when I did this improvement.
Requirements
1.Python 3.6
2.PyTorch 0.4.1
3.OpenCV
4.imgaug
Installation
Get code
git clone https://github.com/xuzheyuan624/yolov3-pytorch.git
cd yolov3-pytorch
Download COCO dataset and COCO APi
cd data
bash get_coco_dataset.sh
Download Pascal VOC dataset
cd data
bash get_voc_dataset.sh
python voc_label.py
Training
1.Download the pretrained darknet weights from Google Drive or Baidu Yun Drive and move it to weights
2.Set up parameters in config.pyormain.py
Start training
python main.py train --name=coco
For training, each epoch trains on 117264 images from the train and validate COCO sets, and test on 4954 images from COCO dataset (some images are lost :() .I have trained for 36 epochs by freezing the darknet layers and got mAP(0.5) = 0.419, it's not good but I think training all layers for 160 epochs will solve this problem.And I will update this if the final result is well.
Image Augmentation
data_transfromshows many image augmentation, but the most effective augmentation is random cropping and multi-scale training, here is some examples for random cropping.

And for multi-scale training:
| global step | image size |
|---|---|
| 0 - 4000 | 13 * 32 |
| 4000 - 8000 | ((0, 3) + 13) * 32 |
| 8000 - 12000 | ((0, 5) + 12) * 32 |
| 12000 - 16000 | ((0, 7) + 11) * 32 |
| 16000 - | ((0, 9) + 10) * 32 |
Evaluate
You can download the official weights from Google Drive or Baidu Yun Drive and put it in weights
Also you can use the weights trained by yourself just by modifying the path of weights in main.py or config.py
Start evaluating
Use COCO APi to calculate mAP
python main.py eval --name==coco
Some results
| Model | mAP(0.5) |
|---|---|
| YOLOv3(paper)(416x416) | 55.3 |
| YOLOv3(paper)(608x608) | 57.9 |
| YOLOv3(this implement)(416x416) | 53.9 |
| YOLOv3(this implement)(608x608) | 56.7 |
Inference
test
You can test a image by:
python main.py test --name=coco --image=test/test3.jpg

demo
You can alse detect a video or run a real-time detection by
python main.py demo --name=coco --video=path
if video=None, it's a real-time detection