Giter VIP home page Giter VIP logo

pytorch_yolov4's Introduction

YOLOv4

This is PyTorch implementation of YOLOv4 which is based on ultralytics/yolov3.

development log

Expand
  • 2021-10-31 - support RS loss, aLRP loss, AP loss.
  • 2021-10-30 - support alpha IoU.
  • 2021-10-20 - design resolution calibration methods.
  • 2021-10-15 - support joint detection, instance segmentation, and semantic segmentation. seg-yolo
  • 2021-10-13 - design ratio yolo.
  • 2021-09-22 - pytorch 1.9 compatibility.
  • 2021-09-21 - support DIM.
  • 2021-09-16 - support Dynamic Head.
  • 2021-08-28 - design domain adaptive training.
  • 2021-08-22 - design re-balance models.
  • 2021-08-21 - support simOTA.
  • 2021-08-14 - design approximation-based methods.
  • 2021-07-27 - design new decoders.
  • 2021-07-22 - support 1) decoupled head, 2) anchor-free, and 3) multi positives in yolox.
  • 2021-07-10 - design distribution-based implicit modeling.
  • 2021-07-06 - support outlooker attention. volo
  • 2021-07-06 - design self emsemble training method.
  • 2021-06-23 - design cross multi-stage correlation module.
  • 2021-06-18 - design cross stage cross correlation module.
  • 2021-06-17 - support cross correlation module. ccn
  • 2021-06-17 - support attention modules. cbam saan
  • 2021-04-20 - support swin transformer. swin
  • 2021-03-16 - design new stem layers.
  • 2021-03-13 - design implicit modeling. nn mf lc
  • 2021-01-26 - support vision transformer. tr
  • 2021-01-26 - design mask objectness.
  • 2021-01-25 - design rotate augmentation.
  • 2021-01-23 - design collage augmentation.
  • 2021-01-22 - support VoVNet, VoVNetv2.
  • 2021-01-22 - support EIoU.
  • 2021-01-19 - support instance segmentation. mask-yolo
  • 2021-01-17 - support anchor-free-based methods. center-yolo
  • 2021-01-14 - support joint detection and classification. classify-yolo
  • 2020-01-02 - design new PRN and CSP-based models.
  • 2020-12-22 - support transfer learning.
  • 2020-12-18 - support non-local series self-attention blocks. gc dnl
  • 2020-12-16 - support down-sampling blocks in cspnet paper. down-c down-d
  • 2020-12-03 - support imitation learning.
  • 2020-12-02 - support squeeze and excitation.
  • 2020-11-26 - support multi-class multi-anchor joint detection and embedding.
  • 2020-11-25 - support joint detection and embedding. track-yolo
  • 2020-11-23 - support teacher-student learning.
  • 2020-11-17 - pytorch 1.7 compatibility.
  • 2020-11-06 - support inference with initial weights.
  • 2020-10-21 - fully supported by darknet.
  • 2020-09-18 - design fine-tune methods.
  • 2020-08-29 - support deformable kernel.
  • 2020-08-25 - pytorch 1.6 compatibility.
  • 2020-08-24 - support channel last training/testing.
  • 2020-08-16 - design CSPPRN.
  • 2020-08-15 - design deeper model. csp-p6-mish
  • 2020-08-11 - support HarDNet. hard39-pacsp hard68-pacsp hard85-pacsp
  • 2020-08-10 - add DDP training.
  • 2020-08-06 - support DCN, DCNv2. yolov4-dcn
  • 2020-08-01 - add pytorch hub.
  • 2020-07-31 - support ResNet, ResNeXt, CSPResNet, CSPResNeXt. r50-pacsp x50-pacsp cspr50-pacsp cspx50-pacsp
  • 2020-07-28 - support SAM. yolov4-pacsp-sam
  • 2020-07-24 - update api.
  • 2020-07-23 - support CUDA accelerated Mish activation function.
  • 2020-07-19 - support and training tiny YOLOv4. yolov4-tiny
  • 2020-07-15 - design and training conditional YOLOv4. yolov4-pacsp-conditional
  • 2020-07-13 - support MixUp data augmentation.
  • 2020-07-03 - design new stem layers.
  • 2020-06-16 - support floating16 of GPU inference.
  • 2020-06-14 - convert .pt to .weights for darknet fine-tuning.
  • 2020-06-13 - update multi-scale training strategy.
  • 2020-06-12 - design scaled YOLOv4 follow ultralytics. yolov4-pacsp-s yolov4-pacsp-m yolov4-pacsp-l yolov4-pacsp-x
  • 2020-06-07 - design scaling methods for CSP-based models. yolov4-pacsp-25 yolov4-pacsp-75
  • 2020-06-03 - update COCO2014 to COCO2017.
  • 2020-05-30 - update FPN neck to CSPFPN. yolov4-yocsp yolov4-yocsp-mish
  • 2020-05-24 - update neck of YOLOv4 to CSPPAN. yolov4-pacsp yolov4-pacsp-mish
  • 2020-05-15 - training YOLOv4 with Mish activation function. yolov4-yospp-mish yolov4-paspp-mish
  • 2020-05-08 - design and training YOLOv4 with FPN neck. yolov4-yospp
  • 2020-05-01 - training YOLOv4 with Leaky activation function using PyTorch. yolov4-paspp PAN

Pretrained Models & Comparison

Model Test Size APtest AP50test AP75test APStest APMtest APLtest cfg weights
YOLOv4 640 50.0% 68.4% 54.7% 30.5% 54.3% 63.3% cfg weights
YOLOv4pacsp-s 640 39.0% 57.8% 42.4% 20.6% 42.6% 50.0% cfg weights
YOLOv4pacsp 640 49.8% 68.4% 54.3% 30.1% 54.0% 63.4% cfg weights
YOLOv4pacsp-x 640 52.2% 70.5% 56.8% 32.7% 56.3% 65.9% cfg weights
YOLOv4pacsp-s-mish 640 40.8% 59.5% 44.3% 22.4% 44.6% 51.8% cfg weights
YOLOv4pacsp-mish 640 50.9% 69.4% 55.5% 31.2% 55.0% 64.7% cfg weights
YOLOv4pacsp-x-mish 640 52.8% 71.1% 57.5% 33.6% 56.9% 66.6% cfg weights
Model Test Size APval AP50val AP75val APSval APMval APLval cfg weights
YOLOv4 640 49.7% 68.2% 54.3% 32.9% 54.8% 63.7% cfg weights
YOLOv4pacsp-s 640 38.9% 57.7% 42.2% 21.9% 43.3% 51.9% cfg weights
YOLOv4pacsp 640 49.4% 68.1% 53.8% 32.7% 54.2% 64.0% cfg weights
YOLOv4pacsp-x 640 51.6% 70.1% 56.2% 35.3% 56.4% 66.9% cfg weights
YOLOv4pacsp-s-mish 640 40.7% 59.5% 44.2% 25.3% 45.1% 53.4% cfg weights
YOLOv4pacsp-mish 640 50.8% 69.4% 55.4% 34.3% 55.5% 65.7% cfg weights
YOLOv4pacsp-x-mish 640 52.6% 71.0% 57.2% 36.4% 57.3% 67.6% cfg weights
archive
Model Test Size APval AP50val AP75val APSval APMval APLval cfg weights
YOLOv4 640 48.4% 67.1% 52.9% 31.7% 53.8% 62.0% cfg weights
YOLOv4pacsp-s 640 37.0% 55.7% 40.0% 20.2% 41.6% 48.4% cfg weights
YOLOv4pacsp 640 47.7% 66.4% 52.0% 32.3% 53.0% 61.7% cfg weights
YOLOv4pacsp-x 640 50.0% 68.3% 54.5% 33.9% 55.4% 63.7% cfg weights
YOLOv4pacsp-s-mish 640 38.8% 57.8% 42.0% 21.6% 43.7% 51.1% cfg weights
YOLOv4pacsp-mish 640 48.8% 67.2% 53.4% 31.5% 54.4% 62.2% cfg weights
YOLOv4pacsp-x-mish 640 51.2% 69.4% 55.9% 35.0% 56.5% 65.0% cfg weights
Model Test Size APval AP50val AP75val APSval APMval APLval cfg weights
YOLOv4 672 47.7% 66.7% 52.1% 30.5% 52.6% 61.4% cfg weights
YOLOv4pacsp-s 672 36.6% 55.5% 39.6% 21.2% 41.1% 47.0% cfg weights
YOLOv4pacsp 672 47.2% 66.2% 51.6% 30.4% 52.3% 60.8% cfg weights
YOLOv4pacsp-x 672 49.3% 68.1% 53.6% 31.8% 54.5% 63.6% cfg weights
YOLOv4pacsp-s-mish 672 38.6% 57.7% 41.8% 22.3% 43.5% 49.3% cfg weights
(+BoF) 640 39.9% 59.1% 43.1% 24.4% 45.2% 51.4% weights
YOLOv4pacsp-mish 672 48.1% 66.9% 52.3% 30.8% 53.4% 61.7% cfg weights
(+BoF) 640 49.3% 68.2% 53.8% 31.9% 54.9% 62.8% weights
YOLOv4pacsp-x-mish 672 50.0% 68.5% 54.4% 32.9% 54.9% 64.0% cfg weights
(+BoF) 640 51.0% 69.7% 55.5% 33.3% 56.2% 65.5% weights

Requirements

docker (recommanded):

# create the docker container, you can change the share memory size if you have more.
nvidia-docker run --name yolov4 -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

local:

pip install -r requirements.txt

※ For running Mish models, please install https://github.com/thomasbrandon/mish-cuda

Training

python train.py --device 0 --batch-size 16 --img 640 640 --data coco.yaml --cfg cfg/yolov4-pacsp.cfg --weights '' --name yolov4-pacsp

Testing

python test.py --img 640 --conf 0.001 --batch 8 --device 0 --data coco.yaml --cfg cfg/yolov4-pacsp.cfg --weights weights/yolov4-pacsp.pt

Citation

@article{bochkovskiy2020yolov4,
  title={{YOLOv4}: Optimal Speed and Accuracy of Object Detection},
  author={Bochkovskiy, Alexey and Wang, Chien-Yao and Liao, Hong-Yuan Mark},
  journal={arXiv preprint arXiv:2004.10934},
  year={2020}
}
@inproceedings{wang2020cspnet,
  title={{CSPNet}: A New Backbone That Can Enhance Learning Capability of {CNN}},
  author={Wang, Chien-Yao and Mark Liao, Hong-Yuan and Wu, Yueh-Hua and Chen, Ping-Yang and Hsieh, Jun-Wei and Yeh, I-Hau},
  booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition Workshops},
  pages={390--391},
  year={2020}
}

Acknowledgements

pytorch_yolov4's People

Contributors

wongkinyiu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pytorch_yolov4's Issues

what about yolov3?

can this code be used with yolov3 and yolov3-tiny,if i have .cfg and .weights files?

speed and activation

Thanks for your great work! I wonder the speed and the map of the yolov4-paspp.py if the activation is replaced with mish and the imgsize is replaced with 608, which is the same as original darknet.
Besides, what are the meaning of '-s' and '-x' in the cfg files? Thank you!

problem and license

There is a problem with multi-scale, and when will the MIT license be granted?

about mAP

Thank you for your repo, it's a great work.
The COCO mAP in YOLOV4 paper is 43.5, but you can achieve 48.5, why is performance improved so much? the large image size?

yolov4.cfg

Thank you for your great job! Can you use yolov4.cfg from darknet for this project when train?

最新的代码PyTorch_YOLOv4-u5中device设置问题

您好!我在用您今天刚更新的代码训练自己的数据集时,在设置device部分出现了错误。
我输入的命令是:sudo python train.py --data bridge.yaml --cfg yolov4x-mish.yaml --weights '' --batch-size 10 --device 0,2
报错:AssertionError: batch-size 10 not multiple of GPU count 4
请问这是怎么回事呢?

UnboundLocalError: local variable 'epoch' referenced before assignment

Traceback (most recent call last):
File "/home/jjliao/code/PyTorch_yolov4/train.py", line 415, in
train() # train normally
File "/home/jjliao/code/PyTorch_yolov4/train.py", line 373, in train
print('%g epochs completed in %.3f hours.\n' % (epoch - start_epoch + 1, (time.time() - t0) / 3600))
UnboundLocalError: local variable 'epoch' referenced before assignment

请问,这个epoch是没有定义嘛?这个需要加全局变量嘛?求解答,谢谢!

got error when loading saved weights

I want to re-train with last saved weights, but I got error like " The size of tensor a (32) must match the size of tensor b (128) at non-singleton dimension 0" in function optimizer.step().
Do I have to convert .pt to .weights ?

Three issues when training my image data(not coco)

It is really great work!Thanks for your project. I try to train my dataset in Pytorch-YOLOv4 and meet three issues.
I imitated YOLOv3 to make data sets and related files, but I reported an error during training:
1.
Traceback (most recent call last):
File "C:/Users/admin/Desktop/PyTorch_YOLOv4-master/train.py", line 398, in
check_git_status()
File "C:\Users\admin\Desktop\PyTorch_YOLOv4-master\utils\utils.py", line 37, in check_git_status
s = subprocess.check_output('if [ -d .git ]; then git fetch && git status -uno; fi', shell=True).decode('utf-8')
File "C:\Users\admin\Anaconda3\lib\subprocess.py", line 336, in check_output
**kwargs).stdout
File "C:\Users\admin\Anaconda3\lib\subprocess.py", line 418, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command 'if [ -d .git ]; then git fetch && git status -uno; fi' returned non-zero exit status

I add "#" in this error line, but meet the second error

Traceback (most recent call last):
File "C:/Users/admin/Desktop/PyTorch_YOLOv4-master/train.py", line 412, in
train() # train normally
File "C:/Users/admin/Desktop/PyTorch_YOLOv4-master/train.py", line 370, in train
print('%g epochs completed in %.3f hours.\n' % (epoch - start_epoch + 1, (time.time() - t0) / 3600))
UnboundLocalError: local variable 'epoch' referenced before assignment

I add "epoch = 0" before line"for epoch in range(start_epoch, epochs)",but meet another error.

The dataset did not enter the training and training finished

ValueError: too many values to unpack (expected 2)

Epoch gpu_mem GIoU obj cls total targets img_size
0/299 22.4G 7.7 6.39 7.86 22 254 640: 0%| | 11/7329 [00:16<3:04:14, 1.51s/it]
Class Images Targets P R [email protected] F1: 0%| | 0/313 [00:01<?, ?it/s]
Traceback (most recent call last):
File "train.py", line 412, in
train() # train normally
File "train.py", line 317, in train
dataloader=testloader)
File "/home/z50015785/PyTorch_YOLOv4-master-AUTHOR2/test.py", line 94, in test
inf_out, train_out = model(imgs, augment=augment) # inference and training outputs
ValueError: too many values to unpack (expected 2)

How to solve this error?

Is mosaic always in use?

Hi! When I use mosaic, do I need to use like a random.randint(0,1) to determine mosaic be True or False?

License

I was wondering what license is associated with this repo?

how to train VOC dataset?

I would like to ask how to train VOC dataset, if I can, how to operate, I am a novice, please give me more advice

Puzzle Issue for Genetic Algorithm

Dear Profess Bochkovskiy, Profess Wang, Profess Liao,
I read your paper with respect, YOLOv4: Optimal Speed and Accuracy of Object Detection. And I have an issue about

We select optimal hyper-parameters while applying genetic algorithms in your paper.
Does it mean that we select optimal hyper-parameters for YOLO v4 with the help of genetic algorithms?
AND could you do me a favor? What are your hyper-parameters? (learning rate? batch size?) How do you design Fitness function? Is the Fitness function mAP or AP?How do you design Fitness function? Is the Fitness function mAP or AP?
I mean that GA is just like a self-learning system and the fitness function give feedback for combinations of different hyperparameters(or gene).Time of calculation for mAP or AP is huge and then taking mAP or AP(the result of YOLO v4) as the fitness function is unrealistic.

I am looking forward to your answer
(English,Traditional Chinese and Simplified Chinese are available.)

Alan D.Chen
Tongji University

训练错误

在输入train命令后命令提示行反馈 Downloading https://pjreddie.com/media/files/''
curl: (22) The requested URL returned error: 403 Forbidden
rm: 无法删除'': 没有那个文件或目录
我可以登录google 但是这个网站无法进入
后续提示在google云盘下载yolov3.weights已成功下载并且放在了weights文件中,望作者解答
thanks

AssertionError: File not found coco\val2017.txt.

I download the hold package from PyTorch_YOLOv4. I had done [pip install -r requirements.txt], and there wasn't any error.
Then I try [python test_half.py --data coco2017.data --cfg yolov4-pacsp.cfg --weights yolov4-pacsp.pt --img 736 --iou-thr 0.7 --batch-size 8], but it pop out an error: [AssertionError: File not found coco\val2017.txt. See https://github.com/ultralytics/yolov3/wiki/Train-Custom-Data]. Which and where should I going to download or how to fix the problem? Thank you very much.

Define Tags

Hi. I might have jumbled up but for clarity can you define the following tags:

  1. PASPP - PANet + Spatial Pyramid Pool?
  2. PACSP - PANet + Cross Stage Partial Net?
  3. PACSP-S
  4. PACSP-X

关于mish_cuda

mish_cuda支持cuda9.2和10.0,但pytorch1.5.1最低支持10.1,请问您的mish_cuda安装没问题嘛,或者说您的pytorch、cuda的版本是?

2020-07-13 - support MixUp data augmentation.

hi, your develop log says "2020-07-13 - support MixUp data augmentation.", but i can not find any relavtive codes in dataset.py. what's wrong?
also, could you tell me whether the repo support self-adversial training in future?

label problem

who can tell me how to create correct txt labels from coco format labels? the txt labels I create contain many negative numbers and they are useless

请问我开启apex的o2进行训练之后,为什么进行到第1091个step就中断了?显示除0错误,该怎么解决呢?

Image sizes 608 - 608 train, 608 test
Using 8 dataloader workers
Starting training for 300 epochs...

 Epoch   gpu_mem      GIoU       obj       cls     total   targets  img_size
 0/299     10.3G      7.81      6.47      7.85      22.1        73       608:   7%|█████▎                                                                 | 1091/14658 [04:57<1:01:38,  3.67it/s]

Traceback (most recent call last):
File "traino2.py", line 417, in
train() # train normally
File "traino2.py", line 278, in train
scaled_loss.backward()
File "/usr/local/python3/lib/python3.7/contextlib.py", line 119, in exit
next(self.gen)
File "/usr/local/python3/lib/python3.7/site-packages/apex/amp/handle.py", line 123, in scale_loss
optimizer._post_amp_backward(loss_scaler)
File "/usr/local/python3/lib/python3.7/site-packages/apex/amp/_process_optimizer.py", line 196, in post_backward_with_master_weights
preexisting_fp32_grads)
File "/usr/local/python3/lib/python3.7/site-packages/apex/amp/scaler.py", line 176, in unscale_with_stashed
out_scale/grads_have_scale, # 1./scale,
ZeroDivisionError: float division by zero

What LICENSE?

Hello, thank you for the repo :)

Could you please tell me what you are going to license this repo as and when you intend to add a LICENSE file (if at all)?

About Training Time compare with Darknet

Hi, thank you very much for your work in Yolo, I have a question about the training time compare with AlexeyAB darknet, that is which is faster when training with the same network cfg (e.g Yolov4.cfg) and the same iterator counts, Because My computer GPU is not so good, so I'm more concerned with training time. Thank you again.

It is supposed to be compatible for relative path in `val2017.txt`

Problem

When I run the basic demo script:

python test_half.py --data coco2017.data --cfg cfg/yolov4-pacsp.cfg --weights weights/yolov4-pacsp.pt --img 736 --iou-thr 0.7 --batch-size 8

It raised exception that the label files had not been found:

Traceback (most recent call last):
  File "test_half.py", line 257, in <module>
    opt.augment)
  File "test_half.py", line 64, in test
    dataset = LoadImagesAndLabels(path, img_size, batch_size, rect=True, single_cls=opt.single_cls)
  File "/path/to/PyTorch_YOLOv4/utils/datasets.py", line 382, in __init__
    assert nf > 0, 'No labels found in %s. See %s' % (os.path.dirname(file) + os.sep, help_url)
AssertionError: No labels found in ./labels/val2017/. See https://github.com/ultralytics/yolov3/wiki/Train-Custom-Data

By diving into the problem, I found it was caused by relative path.
For the coco2017 dataset, the zip file coco2017labels.zip download from data/get_coco2017.sh contains files:

- coco/
    - annotations/
    - images/
    - labels/
    - train2017.txt
    - val2017.txt
    - ...

The content of val2017.txt is like this:

./images/val2017/000000182611.jpg
./images/val2017/000000335177.jpg
./images/val2017/000000278705.jpg
./images/val2017/000000463618.jpg
./images/val2017/000000568981.jpg
...

Here, the paths of images are relative, so the script could not find the label file.

Solution

Refered to Yolov5 project, we can add two line in utils/database.py to support the relative path:

self.img_files = [x.replace('./', parent) if x.startswith('./') else x for x in self.img_files]

I have create a pull request #32

无法下载训练好的权重文件

您好!我在自己的数据集上进行了训练,但是训练完,在进行测试的时候,无法加载训练好的权重文件.pt,请问这是什么原因?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.