# YOLOv3_TensorFlow
### 1. Introduction
This is my implementation of [YOLOv3](https://pjreddie.com/media/files/papers/YOLOv3.pdf) in pure TensorFlow. It contains the full pipeline of training and evaluation on your own dataset. The key features of this repo are:
- Efficient tf.data pipeline
- Weights converter (converting pretrained darknet weights on COCO dataset to TensorFlow checkpoint.)
- Extremely fast GPU non maximum supression.
- Full training pipeline.
- Kmeans algorithm to select prior anchor boxes.
- [ ] Multi-GPU training with sync batch norm. (on working)
### 2. Requirements
- tensorflow >= 1.8.0 (lower versions may work too)
- opencv-python
### 3. Weights convertion
The pretrained darknet weights file can be downloaded [here](https://pjreddie.com/media/files/yolov3.weights). Place this weights file under directory `./data/darknet_weights/` and then run:
```shell
python convert_weight.py
```
Then the converted TensorFlow checkpoint file will be saved to `./data/darknet_weights/` directory.
You can also download the converted TensorFlow checkpoint file by me via [Google Drive link](https://drive.google.com/drive/folders/1mXbNgNxyXPi7JNsnBaxEv1-nWr7SVoQt?usp=sharing) and then place it to the same directory.
### 4. Running demos
There are some demo images and videos under the `./data/demo_data/`. You can run the demo by:
Single image test demo:
```shell
python test_single_image.py ./data/demo_data/messi.jpg
```
Video test demo:
```shell
python video_test.py ./data/demo_data/video.mp4
```
Some results:
![](https://github.com/wizyoung/YOLOv3_TensorFlow/blob/master/data/demo_data/results/dog.jpg?raw=true)
![](https://github.com/wizyoung/YOLOv3_TensorFlow/blob/master/data/demo_data/results/messi.jpg?raw=true)
![](https://github.com/wizyoung/YOLOv3_TensorFlow/blob/master/data/demo_data/results/kite.jpg?raw=true)
Compare the kite detection results with TensorFlow's offical API result [here](https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/img/kites_detections_output.jpg).
(The kite detection result is under input image resolution 1344x896)
#### 5. Inference speed
How fast is the inference speed? With images scaled to 416*416:
| Backbone | GPU | Time(ms) |
| :-------------------- | :------: | :------: |
| Darknet-53 (paper) | Titan X | 29 |
| Darknet-53 (my impl.) | Titan XP | ~23 |
### 6. Training
#### 6.1 Data preparation
(1) annotation file
Generate `train.txt/val.txt/test.txt` files under `./data/my_data/` directory. One line for one image, in the format like `image_absolute_path box_1 box_2 ... box_n`. Box_format: `label_index x_min y_min x_max y_max`.(The origin of coordinates is at the left top corner.)
For example:
```
xxx/xxx/1.jpg 0 453 369 473 391 1 588 245 608 268
xxx/xxx/2.jpg 1 466 403 485 422 2 793 300 809 320
...
```
**NOTE**: **You should leave a blank line at the end of each txt file.**
(2) class_names file:
Generate the `data.names` file under `./data/my_data/` directory. Each line represents a class name.
For example:
```
bird
person
bike
...
```
The COCO dataset class names file is placed at `./data/coco.names`.
(3) prior anchor file:
Using the kmeans algorithm to get the prior anchors:
```
python get_kmeans.py
```
Then you will get 9 anchors and the average IOU. Save the anchors to a txt file.
The COCO dataset anchors offered by YOLO v3 author is placed at `./data/yolo_anchors.txt`, you can use that one too.
**NOTE: The yolo anchors should be scaled to the rescaled new image size. Suppose your image size is [W, H], and the image will be rescale to 416*416 as input, for each generated anchor [anchor_w, anchor_h], you should apply the transformation anchor_w = anchor_w / W * 416, anchor_h = anchor_g / H * 416.**
#### 6.2 Training
Using `train.py`. The parameters are as following:
```shell
$ python train.py -h
usage: train.py [-h] [--train_file TRAIN_FILE] [--val_file VAL_FILE]
[--restore_path RESTORE_PATH]
[--save_dir SAVE_DIR]
[--log_dir LOG_DIR]
[--progress_log_path PROGRESS_LOG_PATH]
[--anchor_path ANCHOR_PATH]
[--class_name_path CLASS_NAME_PATH] [--batch_size BATCH_SIZE]
[--img_size [IMG_SIZE [IMG_SIZE ...]]]
[--total_epoches TOTAL_EPOCHES]
[--train_evaluation_freq TRAIN_EVALUATION_FREQ]
[--val_evaluation_freq VAL_EVALUATION_FREQ]
[--save_freq SAVE_FREQ] [--num_threads NUM_THREADS]
[--prefetech_buffer PREFETECH_BUFFER]
[--optimizer_name OPTIMIZER_NAME]
[--save_optimizer SAVE_OPTIMIZER]
[--learning_rate_init LEARNING_RATE_INIT] [--lr_type LR_TYPE]
[--lr_decay_freq LR_DECAY_FREQ]
[--lr_decay_factor LR_DECAY_FACTOR]
[--lr_lower_bound LR_LOWER_BOUND]
[--restore_part [RESTORE_PART [RESTORE_PART ...]]]
[--update_part [UPDATE_PART [UPDATE_PART ...]]]
```
Check the `train.py` for more details. You should set the parameters yourself.
Some training tricks in my experiment:
(1) Apply the two-stage training strategy:
First stage: Restore `darknet53_body` part weights from COCO checkpoints, train the `yolov3_head` with big learning rate like 1e-3 until the loss reaches to a low level, like less than 1.
Second stage: Restore the weights from the first stage, then train the whole model with small learning rate like 1e-4 or smaller. At this stage remember to restore the optimizer parameters if you use optimizers like adam.
(2) Quick train:
If you want to obtain good results in a short time like in 10 minutes. You can use the coco names but substitute several with real class names in your dataset. In this way you restore the whole pretrained COCO model and get a 80 class classification model, but you only care the class names from your dataset.
### 7. Evaluation
Using `eval.py` to evaluate the validation or test dataset. The parameters are as following:
```shell
$ python eval.py -h
usage: eval.py [-h] [--eval_file EVAL_FILE] [--restore_path RESTORE_PATH]
[--anchor_path ANCHOR_PATH]
[--class_name_path CLASS_NAME_PATH]
[--batch_size BATCH_SIZE]
[--img_size [IMG_SIZE [IMG_SIZE ...]]]
[--num_threads NUM_THREADS]
[--prefetech_buffer PREFETECH_BUFFER]
```
Check the `eval.py` for more details. You should set the parameters yourself.
You will get the loss, recall and precision metrics results, like:
```shell
recall: 0.927, precision: 0.945
total_loss: 0.210, loss_xy: 0.010, loss_wh: 0.025, loss_conf: 0.125, loss_class: 0.050
```
### 8. Other skills
There are many skills you can try during training:
(1) Data augmentation: You can implement your data augmentation like color jittering under `data_augmentation` method in `./utils/data_utils.py`.
(2) Mutil-scale training: You can change the input image scales (i.e. different input resolutions) periodically like the author does in the original paper.
-------
### Credits:
I refer to many fantastic repos during the implementation:
https://github.com/YunYang1994/tensorflow-yolov3
https://github.com/qqwweee/keras-yolo3
https://github.com/eriklindernoren/PyTorch-YOLOv3
https://github.com/pjreddie/darknet
没有合适的资源?快使用搜索试试~ 我知道了~
Python-完整YOLOv3TensorFlow实现支持您自己的数据集培训
共27个文件
py:14个
jpg:6个
readme:3个
需积分: 16 26 下载量 194 浏览量
2019-08-11
04:04:19
上传
评论 5
收藏 2.44MB ZIP 举报
温馨提示
完整YOLO v3 TensorFlow实现,支持您自己的数据集培训
资源推荐
资源详情
资源评论
收起资源包目录
Python-完整YOLOv3TensorFlow实现支持您自己的数据集培训.zip (27个子文件)
wizyoung-YOLOv3_TensorFlow-9c887ef
test_single_image.py 3KB
convert_weight.py 998B
train.py 13KB
utils
plot_utils.py 1KB
nms_utils.py 4KB
data_utils.py 5KB
__init__.py 0B
eval_utils.py 9KB
layer_utils.py 2KB
misc_utils.py 5KB
video_test.py 4KB
model.py 14KB
eval.py 5KB
README.md 7KB
get_kmeans.py 4KB
data
yolo_anchors.txt 69B
logs
readme 37B
my_data
readme 27B
darknet_weights
readme 46B
demo_data
results
messi.jpg 244KB
kite.jpg 403KB
dog.jpg 180KB
messi.jpg 124KB
kite.jpg 1.35MB
dog.jpg 160KB
coco.names 625B
.gitignore 637B
共 27 条
- 1
资源评论
weixin_39840588
- 粉丝: 448
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于Python实现的自动化办公项目.zip
- 基于python实现的基于PyQt5和爬虫的小说阅读系统.zip
- 机械设计整经机上纱自动化sw20非常好的设计图纸100%好用.zip
- Screenshot_20240427_031602.jpg
- 网页PDF_2024年04月26日 23-46-14_QQ浏览器网页保存_QQ浏览器转格式(6).docx
- 直接插入排序,冒泡排序,直接选择排序.zip
- 在排序2的基础上,再次对快排进行优化,其次增加快排非递归,归并排序,归并排序非递归版.zip
- 实现了7种排序算法.三种复杂度排序.三种nlogn复杂度排序(堆排序,归并排序,快速排序)一种线性复杂度的排序.zip
- 冒泡排序 直接选择排序 直接插入排序 随机快速排序 归并排序 堆排序.zip
- 课设-内部排序算法比较 包括冒泡排序、直接插入排序、简单选择排序、快速排序、希尔排序、归并排序和堆排序.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功