Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rebase upstream #264

Open
wants to merge 37 commits into
base: yolov4-large
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
c4c4763
Update README.md
WongKinYiu Nov 16, 2020
053b716
Add files via upload
WongKinYiu Nov 16, 2020
5f5fafd
Create __init__.py
WongKinYiu Nov 16, 2020
22d83f0
Add files via upload
WongKinYiu Nov 16, 2020
855c32f
Create __init__.py
WongKinYiu Nov 16, 2020
d2a65ea
Update README.md
WongKinYiu Nov 17, 2020
f3a476f
Update README.md
WongKinYiu Nov 17, 2020
eb17b4e
Update detect.py
WongKinYiu Nov 18, 2020
4dfcec6
Update README.md
WongKinYiu Dec 2, 2020
3fbfa65
Update train.py
WongKinYiu May 21, 2021
7df8141
Update test.py
WongKinYiu May 21, 2021
372abc8
Update detect.py
WongKinYiu May 21, 2021
3369da7
Update hyp.scratch.yaml
WongKinYiu May 21, 2021
1fd1c6d
Delete common.py
WongKinYiu May 21, 2021
c369792
Delete experimental.py
WongKinYiu May 21, 2021
d60b350
Update export.py
WongKinYiu May 21, 2021
3ebdfcb
Delete yolo.py
WongKinYiu May 21, 2021
8d6011c
Update models.py
WongKinYiu May 21, 2021
2148849
Update activations.py
WongKinYiu May 21, 2021
28b7cd2
Update datasets.py
WongKinYiu May 21, 2021
536312b
Update general.py
WongKinYiu May 21, 2021
f29646c
Update google_utils.py
WongKinYiu May 21, 2021
b1bd227
Update layers.py
WongKinYiu May 21, 2021
8ead5ee
Update parse_config.py
WongKinYiu May 21, 2021
53e2756
Update torch_utils.py
WongKinYiu May 21, 2021
8b3cc06
Create autoanchor.py
WongKinYiu May 21, 2021
99df736
Create loss.py
WongKinYiu May 21, 2021
6b73e1e
Create metric.py
WongKinYiu May 21, 2021
6e0b56d
Create plots.py
WongKinYiu May 21, 2021
4999157
Update models.py
WongKinYiu May 21, 2021
cd21c8f
Update README.md
WongKinYiu May 21, 2021
8aaf0ed
Rename metric.py to metrics.py
WongKinYiu May 21, 2021
0c13b23
Update README.md
WongKinYiu May 21, 2021
e75367e
Update detect.py
WongKinYiu Jun 7, 2021
c505fdb
- created a yolov4 CSP single class config file
kweston Feb 11, 2021
8c76b8b
- added docker-compose.yml file
kweston Feb 11, 2021
31b0ca7
- write error cases to file in test.py
kweston Jun 10, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
runs
weights
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TAG=0.1.0
55 changes: 55 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#FROM nvcr.io/nvidia/pytorch:20.06-py3
#FROM continuumio/miniconda3
#FROM gpuci/miniconda-cuda:11.0-devel-ubuntu20.04
FROM nvidia/cuda:11.1-cudnn8-devel-ubuntu20.04

#COPY environment.yml .
#RUN conda update --force-reinstall conda
#RUN conda env update --name base --file environment.yml --prune

ENV MY_ROOT=/workspace \
PKG_PATH=/yolo_src \
NUMPROC=4 \
PYTHON_VER=3.8 \
PYTHONUNBUFFERED=1 \
PYTHONPATH=. \
DEBIAN_FRONTEND=noninteractive

WORKDIR $PKG_PATH

RUN apt-get update && apt-get install -y apt-utils && apt-get -y upgrade && \
apt-get install -y git libsnappy-dev libopencv-dev libhdf5-serial-dev libboost-all-dev libatlas-base-dev \
libgflags-dev libgoogle-glog-dev liblmdb-dev curl unzip\
python${PYTHON_VER}-dev && \
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py && \
python${PYTHON_VER} get-pip.py && \
rm get-pip.py && \
# Clean UP
apt upgrade -y && \
apt clean && \
apt autoremove -y && \
rm -rf /var/lib/apt/lists/* # cleanup to reduce image size

RUN ln -s /usr/bin/python${PYTHON_VER} /usr/bin/python

RUN apt install unzip
RUN pip install torch==1.7.1+cu110 torchvision==0.8.2+cu110 -f https://download.pytorch.org/whl/torch_stable.html

WORKDIR $MY_ROOT
# We have to install mish-cuda from source due to an issue with one of the header files
ADD https://github.com/thomasbrandon/mish-cuda/archive/master.zip $MY_ROOT/mish-cuda.zip
RUN unzip mish-cuda.zip
WORKDIR $MY_ROOT/mish-cuda-master
RUN cp external/CUDAApplyUtils.cuh csrc/
RUN python setup.py build install
WORKDIR $PKG_PATH
# ADD https://drive.google.com/file/d/1NQwz47cW0NUgy7L3_xOKaNEfLoQuq3EL/view?usp=sharing /weights/yolov4-csp.weights
ADD requirements.txt $PKG_PATH/requirements.txt
RUN pip install -r $PKG_PATH/requirements.txt
ADD yolo $PKG_PATH/yolo
ADD train.py $PKG_PATH/train.py
ADD test.py $PKG_PATH/test.py
ADD setup.py $PKG_PATH/setup.py
ADD data $PKG_PATH/data
RUN pip install .

111 changes: 110 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,110 @@
# scaledYOLOv4
# YOLOv4-CSP

This is the implementation of "[Scaled-YOLOv4: Scaling Cross Stage Partial Network](https://arxiv.org/abs/2011.08036)" using PyTorch framwork.

* **2021.05.21** Due to unknown issue some people can not reproduce the performance in paper and I can not reproduce the [issue#89](https://github.com/WongKinYiu/ScaledYOLOv4/issues/89), I update the codebase. But it will makes the reproduce performance becomes better than paper (47.8 AP -> 48.7 AP).

* **2020.11.16** Now supported by [Darknet](https://github.com/AlexeyAB/darknet). [`yolov4-csp.cfg`](https://github.com/AlexeyAB/darknet/blob/master/cfg/yolov4-csp.cfg) [`yolov4-csp.weights`](https://drive.google.com/file/d/1TdKvDQb2QpP4EhOIyks8kgT8dgI1iOWT/view?usp=sharing)

## Installation

```
# create the docker container, you can change the share memory size if you have more.
nvidia-docker run --name yolov4_csp -it -v your_coco_path/:/coco/ -v your_code_path/:/yolo --shm-size=64g nvcr.io/nvidia/pytorch:20.11-py3

# apt install required packages
apt update
apt install -y zip htop screen libgl1-mesa-glx

# pip install required packages
pip install seaborn thop

# install mish-cuda if you want to use mish activation
# https://github.com/thomasbrandon/mish-cuda
# https://github.com/JunnYu/mish-cuda
cd /
git clone https://github.com/JunnYu/mish-cuda
cd mish-cuda
python setup.py build install

# go to code folder
cd /yolo
```

## Testing

[`yolov4-csp.weights`](https://drive.google.com/file/d/1TdKvDQb2QpP4EhOIyks8kgT8dgI1iOWT/view?usp=sharing)

<details><summary> <b>old weights</b> </summary>

[`yolov4-csp.weights`](https://drive.google.com/file/d/1NQwz47cW0NUgy7L3_xOKaNEfLoQuq3EL/view?usp=sharing)

</details>

```
# download yolov4-csp.weights and put it in /yolo/weights/ folder.
python test.py --img 640 --conf 0.001 --iou 0.65 --batch 8 --device 0 --data coco.yaml --cfg models/yolov4-csp.cfg --weights weights/yolov4-csp.weights
```

You will get the results:
```
Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.48656
Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.67002
Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.52739
Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.33082
Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.54036
Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.62107
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.37197
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.61211
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.66544
Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.49676
Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.72018
Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.80528
```
<details><summary> <b>old results</b> </summary>

```
Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.47827
Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.66448
Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.51928
Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.30647
Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.53106
Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.61056
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.36823
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.60434
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.65795
Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.48486
Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.70892
Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.79914
```

</details>

## Training

```
# you can change batch size to fit your GPU RAM.
python train.py --device 0 --batch-size 16 --data coco.yaml --cfg yolov4-csp.cfg --weights '' --name yolov4-csp
```

For resume training:
```
# assume the checkpoint is stored in runs/train/yolov4-csp/weights/.
python train.py --device 0 --batch-size 16 --data coco.yaml --cfg yolov4-csp.cfg --weights 'runs/train/yolov4-csp/weights/last.pt' --name yolov4-csp --resume
```

If you want to use multiple GPUs for training
```
python -m torch.distributed.launch --nproc_per_node 4 train.py --device 0,1,2,3 --batch-size 64 --data coco.yaml --cfg yolov4-csp.cfg --weights '' --name yolov4-csp --sync-bn
```

## Citation

```
@article{wang2020scaled,
title={{Scaled-YOLOv4}: Scaling Cross Stage Partial Network},
author={Wang, Chien-Yao and Bochkovskiy, Alexey and Liao, Hong-Yuan Mark},
journal={arXiv preprint arXiv:2011.08036},
year={2020}
}
```
80 changes: 80 additions & 0 deletions data/coco.names
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
person
bicycle
car
motorcycle
airplane
bus
train
truck
boat
traffic light
fire hydrant
stop sign
parking meter
bench
bird
cat
dog
horse
sheep
cow
elephant
bear
zebra
giraffe
backpack
umbrella
handbag
tie
suitcase
frisbee
skis
snowboard
sports ball
kite
baseball bat
baseball glove
skateboard
surfboard
tennis racket
bottle
wine glass
cup
fork
knife
spoon
bowl
banana
apple
sandwich
orange
broccoli
carrot
hot dog
pizza
donut
cake
chair
couch
potted plant
bed
dining table
toilet
tv
laptop
mouse
remote
keyboard
cell phone
microwave
oven
toaster
sink
refrigerator
book
clock
vase
scissors
teddy bear
hair drier
toothbrush
19 changes: 19 additions & 0 deletions data/coco.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# train and val datasets (image directory or *.txt file with image paths)
train: /mnt/coco/5k.txt # 118k images
#val: /mnt/coco/5k.txt # 5k images
val: data/coco_5k_500_subset.txt
test: data/coco_5k_500_subset.txt # 20k images for submission to https://competitions.codalab.org/competitions/20794

# number of classes
nc: 80

# class names
names: ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light',
'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow',
'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee',
'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard',
'tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple',
'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch',
'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone',
'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear',
'hair drier', 'toothbrush']
28 changes: 28 additions & 0 deletions data/hyp.scratch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3)
lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf)
momentum: 0.937 # SGD momentum/Adam beta1
weight_decay: 0.0005 # optimizer weight decay 5e-4
warmup_epochs: 3.0 # warmup epochs (fractions ok)
warmup_momentum: 0.8 # warmup initial momentum
warmup_bias_lr: 0.1 # warmup initial bias lr
box: 0.05 # box loss gain
cls: 0.3 # cls loss gain
cls_pw: 1.0 # cls BCELoss positive_weight
obj: 0.7 # obj loss gain (scale with pixels)
obj_pw: 1.0 # obj BCELoss positive_weight
iou_t: 0.20 # IoU training threshold
anchor_t: 4.0 # anchor-multiple threshold
# anchors: 3 # anchors per output layer (0 to ignore)
fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5)
hsv_h: 0.015 # image HSV-Hue augmentation (fraction)
hsv_s: 0.7 # image HSV-Saturation augmentation (fraction)
hsv_v: 0.4 # image HSV-Value augmentation (fraction)
degrees: 0.0 # image rotation (+/- deg)
translate: 0.1 # image translation (+/- fraction)
scale: 0.9 # image scale (+/- gain)
shear: 0.0 # image shear (+/- deg)
perspective: 0.0 # image perspective (+/- fraction), range 0-0.001
flipud: 0.0 # image flip up-down (probability)
fliplr: 0.5 # image flip left-right (probability)
mosaic: 1.0 # image mosaic (probability)
mixup: 0.0 # image mixup (probability)
10 changes: 10 additions & 0 deletions data/speedco.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# train and val datasets (image directory or *.txt file with image paths)
train: data/speedco_dataset_train_images.txt
val: data/speedco_dataset_val_images.txt
test: data/speedco_dataset_val_images.txt

# number of classes
nc: 1

# class names
names: ['truck']
Loading