Git Product home page Git Product logo

yolov2-yolov3_pytorch's Introduction

Update

Recently, I have released a new YOLO project:

https://github.com/yjh0410/PyTorch_YOLO_Tutorial

In my new YOLO project, you can enjoy:

  • a new and stronger YOLOv1
  • a new and stronger YOLOv2
  • YOLOv3
  • YOLOv4
  • YOLOv5
  • YOLOv7
  • YOLOX
  • RTCDet

This project

In this project, you can enjoy:

  • YOLOv2 with DarkNet-19
  • YOLOv2 with ResNet-50
  • YOLOv2Slim
  • YOLOv3
  • YOLOv3-Spp
  • YOLOv3-Tiny

I just want to provide a good YOLO project for everyone who is interested in Object Detection.

Weights

Google Drive: https://drive.google.com/drive/folders/1T5hHyGICbFSdu6u2_vqvxn_puotvPsbd?usp=sharing

BaiDuYunDisk: https://pan.baidu.com/s/1tSylvzOVFReUAvaAxKRSwg Password d266

You can download all my models from the above links.

YOLOv2

YOLOv2 with DarkNet-19

Tricks

Tricks in official paper:

  • batch norm
  • hi-res classifier
  • convolutional
  • anchor boxes
  • new network
  • dimension priors
  • location prediction
  • passthrough
  • multi-scale
  • hi-red detector

VOC2007

size Original (darknet) Ours (pytorch) 160peochs Ours (pytorch) 250epochs
VOC07 test 416 76.8 76.0 77.1
VOC07 test 544 78.6 77.0 78.1

COCO

data AP AP50 AP75 AP_S AP_M AP_L
Original (darknet) COCO test-dev 21.6 44.0 19.2 5.0 22.4 35.5
Ours (pytorch) COCO test-dev 26.8 46.6 26.8 5.8 27.4 45.2
Ours (pytorch) COCO eval 26.6 46.0 26.7 5.9 27.8 47.1

YOLOv2 with ResNet-50

I replace darknet-19 with resnet-50 and get a better result on COCO-val

data AP AP50 AP75 AP_S AP_M AP_L
Our YOLOv2-320 COCO eval 25.8 44.6 25.9 4.6 26.8 47.9
Our YOLOv2-416 COCO eval 29.0 48.8 29.7 7.4 31.9 48.3
Our YOLOv2-512 COCO eval 30.4 51.6 30.9 10.1 34.9 46.6
Our YOLOv2-544 COCO eval 30.4 51.9 30.9 11.1 35.8 45.5
Our YOLOv2-608 COCO eval 29.2 51.6 29.1 13.6 36.8 40.5

YOLOv3

VOC2007

size Original (darknet) Ours (pytorch) 250epochs
VOC07 test 416 80.25 81.4

COCO

Official YOLOv3:

data AP AP50 AP75 AP_S AP_M AP_L
YOLOv3-320 COCO test-dev 28.2 51.5 - - - -
YOLOv3-416 COCO test-dev 31.0 55.3 - - - -
YOLOv3-608 COCO test-dev 33.0 57.0 34.4 18.3 35.4 41.9

Our YOLOv3:

data AP AP50 AP75 AP_S AP_M AP_L
YOLOv3-320 COCO test-dev 33.1 54.1 34.5 12.1 34.5 49.6
YOLOv3-416 COCO test-dev 36.0 57.4 37.0 16.3 37.5 51.1
YOLOv3-608 COCO test-dev 37.6 59.4 39.9 20.4 39.9 48.2

YOLOv3SPP

COCO:

data AP AP50 AP75 AP_S AP_M AP_L
YOLOv3Spp-320 COCO eval 32.78 53.79 33.9 12.4 35.5 50.6
YOLOv3Spp-416 COCO eval 35.66 57.09 37.4 16.8 38.1 50.7
YOLOv3Spp-608 COCO eval 37.52 59.44 39.3 21.5 40.6 49.6

YOLOv3Tiny

data AP AP50 AP75 AP_S AP_M AP_L
(official) YOLOv3Tiny COCO test-dev - 33.1 - - - -
(Our) YOLOv3Tiny COCO val 15.9 33.8 12.8 7.6 17.7 22.4

Installation

  • Pytorch-gpu 1.1.0/1.2.0/1.3.0
  • Tensorboard 1.14.
  • opencv-python, python3.6/3.7

Dataset

VOC Dataset

I copy the download files from the following excellent project: https://github.com/amdegroot/ssd.pytorch

I have uploaded the VOC2007 and VOC2012 to BaiDuYunDisk, so for researchers in China, you can download them from BaiDuYunDisk:

Link:https://pan.baidu.com/s/1tYPGCYGyC0wjpC97H-zzMQ

Password:4la9

You will get a VOCdevkit.zip, then what you need to do is just to unzip it and put it into data/. After that, the whole path to VOC dataset is data/VOCdevkit/VOC2007 and data/VOCdevkit/VOC2012.

Download VOC2007 trainval & test

# specify a directory for dataset to be downloaded into, else default is ~/data/
sh data/scripts/VOC2007.sh # <directory>

Download VOC2012 trainval

# specify a directory for dataset to be downloaded into, else default is ~/data/
sh data/scripts/VOC2012.sh # <directory>

MSCOCO Dataset

I copy the download files from the following excellent project: https://github.com/DeNA/PyTorch_YOLOv3

Download MSCOCO 2017 dataset

Just run sh data/scripts/COCO2017.sh. You will get COCO train2017, val2017, test2017.

Train

VOC

python train.py -d voc --cuda -v [select a model] -hr -ms --ema

You can run python train.py -h to check all optional argument.

COCO

If you have only one gpu:

python train.py -d coco --cuda -v [select a model] -hr -ms --ema

If you have multi gpus like 8, and you put 4 images on each gpu:

python -m torch.distributed.launch --nproc_per_node=8 train.py -d coco --cuda -v [select a model] -hr -ms --ema \
                                                                        -dist \
                                                                        --sybn \
                                                                        --num_gpu 8\
                                                                        --batch_size 4

Test

VOC

python test.py -d voc --cuda -v [select a model] --trained_model [ Please input the path to model dir. ]

COCO

python test.py -d coco-val --cuda -v [select a model] --trained_model [ Please input the path to model dir. ]

Evaluation

VOC

python eval.py -d voc --cuda -v [select a model] --train_model [ Please input the path to model dir. ]

COCO

To run on COCO_val:

python eval.py -d coco-val --cuda -v [select a model] --train_model [ Please input the path to model dir. ]

To run on COCO_test-dev(You must be sure that you have downloaded test2017):

python eval.py -d coco-test --cuda -v [select a model] --train_model [ Please input the path to model dir. ]

You will get a .json file which can be evaluated on COCO test server.

yolov2-yolov3_pytorch's People

Contributors

developer0hye avatar hit-k544 avatar yjh0410 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

yolov2-yolov3_pytorch's Issues

Cannot find rule for <class 'torch.nn.modules.container.Sequential'>. Treat it as zero Macs and zero Params.

At the begining there are some WARNs
[WARN] Cannot find rule for <class 'torch.nn.modules.container.Sequential'>. Treat it as zero Macs and zero Params.
[WARN] Cannot find rule for <class 'backbone.darknet.Conv_BN_LeakyReLU'>. Treat it as zero Macs and zero Params.
[WARN] Cannot find rule for <class 'backbone.darknet.DarkNet_19'>. Treat it as zero Macs and zero Params.
[WARN] Cannot find rule for <class 'utils.modules.Conv'>. Treat it as zero Macs and zero Params.
[WARN] Cannot find rule for <class 'utils.modules.reorg_layer'>. Treat it as zero Macs and zero Params.
[WARN] Cannot find rule for <class 'models.yolov2_d19.YOLOv2D19'>. Treat it as zero Macs and zero Params.

And it will stop at 3rd epoch and raise error when I train:
Traceback (most recent call last):
File "train.py", line 474, in
train()
File "train.py", line 432, in train
dist.barrier()
File "/home/ggy/anaconda3/lib/python3.8/site-packages/torch/distributed/distributed_c10d.py", line 1959, in barrier
_check_default_pg()
File "/home/ggy/anaconda3/lib/python3.8/site-packages/torch/distributed/distributed_c10d.py", line 210, in _check_default_pg
assert _default_pg is not None,
AssertionError: Default process group is not initialized

That's my param:
python train.py -d coco --cuda -v yolov2_d19 -hr -ms --ema

How can I solve this problem?
Thanks!

utils.modules.Conv2d seems wrong

As far as I know, a convolutional layer should not have bias when a Batch Normalization applied after it. I think it is a serious issue according to the theory of Batch Normalization. I would appreciate if you learn more about Batch Normalization and fix the issue.
Thus you can add a bias=False as a kwarg of torch.nn.Conv2d in utils.modules.Conv2d module, then retrain the models.

about loss function

"txty_loss_function = nn.BCEWithLogitsLoss(reduction='none')" doesn't match the original paper?
can you explain it.

thanks!!

A question abount num_classes

Hey friend. I just want to use the COCO dataset to train a model that is used to detect people. That's means I only have one class to predict. But I have a question about the value of the "num_classes". Does the "num_classes" include "background"? 1 or 2 should I write?

class YOLO里的nms函数是否有错

ins = np.where(iou <= self.nms_threshold)[0]
orders = orders[ins+1]

这里是否要修改为:
ins = np.where(iou <= self.nms_threshold)
orders = orders[ins]

how to apply your code on other dataset?

Hi, thanks for your nice job!
I want to apply your code on other dataset (such as fire detection), however, in this case, num of case is only 1 (20 for voc and 80 for coco). So, should I remove the loss part for classification(because there exists loss for object confidence) , or just change number of class to 1?

mis match erros in training Yolo_v2

env

  • GPU 2080ti
  • ubuntu 16.04
  • python 3.6
  • pytorch 1.5.0

errors

when i use yolo-v2 to train the voc dataset, and set the parameters as follows:

parser.add_argument('-v', '--version', default='yolo_v2',
                        help='yolo_v2, yolo_v3, slim_yolo_v2, tiny_yolo_v3')

    parser.add_argument('-d', '--dataset', default='VOC',
                        help='VOC or COCO dataset')

    parser.add_argument('-hr', '--high_resolution', action='store_true', default=True,
                        help='use high resolution to pretrain.')

    parser.add_argument('-ms', '--multi_scale', action='store_true', default=True,
                        help='use multi-scale trick')

    parser.add_argument('--batch_size', default=32, type=int,
                        help='Batch size for training')

    parser.add_argument('--lr', default=1e-3, type=float,
                        help='initial learning rate')

    parser.add_argument('-cos', '--cos', action='store_true', default=False,
                        help='use cos lr')

    parser.add_argument('-no_wp', '--no_warm_up', action='store_true', default=False,
                        help='yes or no to choose using warmup strategy to train')

    parser.add_argument('--wp_epoch', type=int, default=2,
                        help='The upper bound of warm-up')

    parser.add_argument('--dataset_root', default="/home/xxx/tmp/tmp/yolo_v1_v2/data/VOCdevkit",
                        help='Location of VOC root directory')

    parser.add_argument('--num_classes', default=20, type=int,
                        help='The number of dataset classes')

    parser.add_argument('--momentum', default=0.9, type=float,
                        help='Momentum value for optim')

    parser.add_argument('--weight_decay', default=5e-4, type=float,
                        help='Weight decay for SGD')

    parser.add_argument('--gamma', default=0.1, type=float,
                        help='Gamma update for SGD')

    parser.add_argument('--num_workers', default=8, type=int,
                        help='Number of workers used in dataloading')

    parser.add_argument('--cuda', action='store_true', default=True,
                        help='use cuda.')

    parser.add_argument('--save_folder', default='weights/voc/', type=str,
                        help='Gamma update for SGD')

    parser.add_argument('--tfboard', action='store_true', default=False,
                        help='use tensorboard')

    parser.add_argument('--resume', type=str, default=None,
                        help='fine tune the model trained on MSCOCO.')

An error occured while running the code, it looks like mismatch the size in somewhere, but when i set the multi-scale False, the code is working well. So i think there must be something wrong with multi-scale.

[Epoch 1/250][Iter 0/517][lr 0.000000][Loss: obj 433.45 || cls 8.17 || bbox 19.32 || total 460.94 || size 608 || time: 13.28]
[Epoch 1/250][Iter 10/517][lr 0.000000][Loss: obj 431.94 || cls 7.31 || bbox 13.79 || total 453.04 || size 608 || time: 9.52]
Traceback (most recent call last):
  File "/home/xxx/tmp/tmp/yolo_v1_v2/train_voc.py", line 294, in <module>
    train()
  File "/home/xxx/tmp/tmp/yolo_v1_v2/train_voc.py", line 245, in train
    conf_loss, cls_loss, txtytwth_loss, total_loss = model(images, target=targets)
  File "/home/xxx/anaconda3/envs/pytorch1.5.0/lib/python3.7/site-packages/torch/nn/modules/module.py", line 550, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/xxx/tmp/tmp/yolo_v1_v2/models/yolo_v2.py", line 217, in forward
    x1y1x2y2_pred = (self.decode_boxes(txtytwth_pred) / self.scale_torch).view(-1, 4)
  File "/home/xxx/tmp/tmp/yolo_v1_v2/models/yolo_v2.py", line 90, in decode_boxes
    xywh_pred = self.decode_xywh(txtytwth_pred)
  File "/home/xxx/tmp/tmp/yolo_v1_v2/models/yolo_v2.py", line 74, in decode_xywh
    xy_pred = torch.sigmoid(txtytwth_pred[:, :, :, :2]) + self.grid_cell
RuntimeError: The size of tensor a (361) must match the size of tensor b (100) at non-singleton dimension 1

Normalized WH Prediction seems to get better performance

https://github.com/developer0hye/YOLOv3-PyTorch-Colab

https://colab.research.google.com/drive/1ikcj4kJ2N1ny3jIHuEFIZTnwlV9-nCw4

I am experimenting with the variant of your code.

I got the higher mAP with normalized wh prediction instead of wh divided by the stride.

The results of 170 epoch trained yolv3 tiny

AP for aeroplane = 0.7843
AP for bicycle = 0.8139
AP for bird = 0.6702
AP for boat = 0.6116
AP for bottle = 0.5703
AP for bus = 0.8028
AP for car = 0.8394
AP for cat = 0.8012
AP for chair = 0.5465
AP for cow = 0.7497
AP for diningtable = 0.6677
AP for dog = 0.7366
AP for horse = 0.8391
AP for motorbike = 0.8023
AP for person = 0.7880
AP for pottedplant = 0.4613
AP for sheep = 0.7257
AP for sofa = 0.6991
AP for train = 0.8025
AP for tvmonitor = 0.7194
Mean AP = 0.7216

Why does box_w only divide by strides [-1]

Hello, I would like to ask you a question:
In the multi_gt_creator function of the tools.py file, why does box_w only divide by strides [-1] before calculating iou, does this not always cause iou to be calculated on the minimum or maximum downsampling multiple? Instead of calculating at all downsampling multiples.

box_ws = box_w / strides[-1]
box_hs = box_h / strides[-1]

Class Prediction Softmax vs Sigmoid

Have you trained and tested your model using Sigmoid function instead of Softmax function?

In the YOLOv3 paper, the author mentioned that sigmoid function is used to predict multi-class.
Actually, I compared the mAP of 50 epoch trained 2 models with sigmoid and softmax and I observed that the model with softmax has higher mAP. But, I think 50 epochs trained model is not sufficient to compare the performance.

Multiple processes of training

Hello @yjh0410,

Thanks for the share of your work! I am training the yolov2 darknet19 model on my machine, and have realized 2 problems:

  1. After some time, training stops although the training process is running. I realized this only after forwarding the stdouts to be logged into a txt file, and had to kill and resume training 5 times within 120 epochs to be able to continue.
  2. When the training pid is killed, the memory of the gpus didn't get flushed out. When I do sudo fuser -v /dev/nvidia*, I saw that 8 more processes were created along with the parent process shown on nvtop/nvidia-smi. Do you know why 9 instances of the same process are created when the code isn't multithreaded?
    image

I'm running on ubuntu 18.04 lts, python 3.7.6, torch 1.7.0 and using GeForce GTX 1080 Ti.

Can this code run on GeForce GTX 2080 Ti?

Hello @yjh0410,
Thanks for the share of your work! I am training the yolov2slim model on my machine, and meet a problem:when I use 3 GPUs to train the yolov2slim model on COCO2017 dataset. When I log in to the server again after running the code in the background, the connection fails.Here are my circumstances and instructions :
python 3.6.0 torch 1.6.0 torchvision 0.7.0
nohup python -m torch.distributed.launch --nproc_per_node=3 train.py
-dist
--sybn
--num_gpu 3
--batch_size 96 &

Random Crash during Training

My environment

GPU: gtx1080ti
Cuda: 9.2
Cudnn: not download

The program crashes during training sometimes, have you ever experienced the crash?

About training yolov3 gradient explode problem

image
When I trained YOLOV3 at Batch Size = 4, ‘nan’ appeared. After Debug, I found the infinite number appears at models/yolov3.py 118th code,
This is because the output of the network txtytwth_pred [:::,:, 2:] some values are too large, resulting in an infinite exp value.

Therefore, this is not the author's implementation problem, it is the reason for the unstable training, so I reduced the learning rate to 1e-4, and the training was normal.
Hope can help to other friend.

The infer speed is too slow

First of all, thank you for your work and open source,The problem I met before was caused by a mistake of mine. But I still want to make suggestions to you, you can post the performance of the infer speed

Share Pre-trained weight with Google Drive

Thanks for sharing your great works.

I tried to download your ImageNet pretrained weight file with baidu. But I failed to it.

Could you share pre-trained weight with Google drive?

The Input Image Normalization Policy used in your pretrained backbone network

Thanks for sharing great works!

I have one question.

What is your input image normalization policy used in pretrained backbone network?

Did you put the image into model without normalization?

Is the range [0, 255]? or you followed the normalization method proposed in VGG(Z-normalization using mean and std)?

Please add license

It would be great if you could add a license so we know how we may use the code! Thank you!

[WARN] Cannot find rule for <class 'torch.nn.modules.container.Sequential'>. Treat it as zero Macs and zero Params.

I met this warn when I type the commad python train.py -v yolov2_r50 in the terminate

[WARN] Cannot find rule for <class 'torch.nn.modules.container.Sequential'>. Treat it as zero Macs and zero Params.
[WARN] Cannot find rule for <class 'backbone.resnet.Bottleneck'>. Treat it as zero Macs and zero Params.
[WARN] Cannot find rule for <class 'backbone.resnet.ResNet'>. Treat it as zero Macs and zero Params.

I just can't figure out the reason why this warn occured and hope you can help me
thank you!

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.