linzino7 / pytorch-YOLOv4

PyTorch ,ONNX and TensorRT implementation of YOLOv4

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pytorch-YOLOv4

A minimal PyTorch implementation of YOLOv4.

This Rep forked from Tianxiaomo/pytorch-YOLOv4. See Original_README.

Hardware

  • Ubuntu 18.04 LTS
  • Intel(R) Core(TM) i7-6900K CPU @ 3.20GHz
  • 31 RAM
  • NVIDIA RTX 1080 8G * 4

Reproducing Submission

To reproduct my submission without retrainig, do the following steps:

  1. Dataset Preparation
  2. Training
  3. Inference

Pytorch Weights Download

Dataset Preparation

All required files except images are already in data directory. If you generate CSV files (duplicate image list, split, leak.. ), original files are overwritten. The contents will be changed, but It's not a problem.

Prepare Images

After downloading images, the data directory is structured as:

train.txt
  +- data/
  | +- train/
  | +- test/
  | +- training_labels.csv
  | +- val.txt

Download Classes Image

Smaill SVHN Dataset: https://drive.google.com/drive/u/1/folders/1Ob5oT9Lcmz7g5mVOcYH3QugA7tV3WsSl

Download and extract tain.tar.gz and test.tar.gz to data directory.

Transform data

Use construct_datasets.py to make train.txt .

# train.txt and val.txt  
# left(x1) top(y1)  right(x2) bottom(y2) label
image_path1 x1,y1,x2,y2,id x1,y1,x2,y2,id x1,y1,x2,y2,id ...
image_path2 x1,y1,x2,y2,id x1,y1,x2,y2,id x1,y1,x2,y2,id ...
...

Names file example is in data/SVHN.names

# names file
Label1
Label2
Label3
...

Training

Setting

You can setting bach size and epoch in cfg.py

Train models

To train models, run following commands.

$ python3 train.py -d data/ -classes 10 -g 0 -pretrained ./weight/yolov4.conv.137.pth

The expected training times are:

Model GPUs Image size Training Epochs Training Time Bach Size
YOLOv4 1x NVIDIA T4 608x608 1 2.5 hours 4
YOLOv4 4x NVIDIA GTX 1080 608x608 1 0.6 hour 32

Muti-GPU Training

$ python3 train.py -d data/ -classes 10 -g 0,1,2,3 -pretrained ./weight/yolov4.conv.137.pth

Inference

Inference single images

$ python3 models.py 10 Yolov4_epoch10.pth data/test/1.png 608 608 data/SVHN.names

Inference images in folder

$ python3 models_mut.py 10 Yolov4_epoch22_pre.pth data/test/ 608 608 data/SVHN.names

Result

mAP: 0.51742 90ms per image

Reference:

About

PyTorch ,ONNX and TensorRT implementation of YOLOv4

License:Apache License 2.0


Languages

Language:Python 76.8%Language:C++ 21.7%Language:Cuda 0.9%Language:Makefile 0.6%