Giter VIP home page Giter VIP logo

yolo-v2-pytorch's Introduction

[PYTORCH] YOLO (You Only Look Once)

Introduction

Here is my pytorch implementation of the model described in the paper YOLO9000: Better, Faster, Stronger paper.


An example of my model's output.

How to use my code

With my code, you can:

  • Train your model from scratch
  • Train your model with my trained model
  • Evaluate test images with either my trained model or yours

Requirements:

  • python 3.6
  • pytorch 0.4
  • opencv (cv2)
  • tensorboard
  • tensorboardX (This library could be skipped if you do not use SummaryWriter)
  • numpy

Datasets:

I used 4 different datases: VOC2007, VOC2012, COCO2014 and COCO2017. Statistics of datasets I used for experiments is shown below

Dataset Classes #Train images/objects #Validation images/objects
VOC2007 20 5011/12608 4952/-
VOC2012 20 5717/13609 5823/13841
COCO2014 80 83k/- 41k/-
COCO2017 80 118k/- 5k/-

Create a data folder under the repository,

cd {repo_root}
mkdir data
  • VOC: Download the voc images and annotations from VOC2007 or VOC2012. Make sure to put the files as the following structure:

    VOCDevkit
    ├── VOC2007
    │   ├── Annotations  
    │   ├── ImageSets
    │   ├── JPEGImages
    │   └── ...
    └── VOC2012
        ├── Annotations  
        ├── ImageSets
        ├── JPEGImages
        └── ...
    
  • COCO: Download the coco images and annotations from coco website. Make sure to put the files as the following structure:

    COCO
    ├── annotations
    │   ├── instances_train2014.json
    │   ├── instances_train2017.json
    │   ├── instances_val2014.json
    │   └── instances_val2017.json
    │── images
    │   ├── train2014
    │   ├── train2017
    │   ├── val2014
    │   └── val2017
    └── anno_pickle
        ├── COCO_train2014.pkl
        ├── COCO_val2014.pkl
        ├── COCO_train2017.pkl
        └── COCO_val2017.pkl
    

Setting:

  • Model structure: In compared to the paper, I changed structure of top layers, to make it converge better. You could see the detail of my YoloNet in src/yolo_net.py.
  • Data augmentation: I performed dataset augmentation, to make sure that you could re-trained my model with small dataset (~500 images). Techniques applied here includes HSV adjustment, crop, resize and flip with random probabilities
  • Loss: The losses for object and non-objects are combined into a single loss in my implementation
  • Optimizer: I used SGD optimizer and my learning rate schedule is as follows:
Epoches Learning rate
0-4 1e-5
5-79 1e-4
80-109 1e-5
110-end 1e-6
  • In my implementation, in every epoch, the model is saved only when its loss is the lowest one so far. You could also use early stopping, which could be triggered by specifying a positive integer value for parameter es_patience, to stop training process when validation loss has not been improved for es_patience epoches.

Trained models

You could find all trained models I have trained in YOLO trained models

Training

For each dataset, I provide 2 different pre-trained models, which I trained with corresresponding dataset:

  • whole_model_trained_yolo_xxx: The whole trained model.
  • only_params_trained_yolo_xxx: The trained parameters only.

You could specify which trained model file you want to use, by the parameter pre_trained_model_type. The parameter pre_trained_model_path then is the path to that file.

If you want to train a model with a VOC dataset, you could run:

  • python3 train_voc.py --year year: For example, python3 train_voc.py --year 2012

If you want to train a model with a COCO dataset, you could run:

  • python3 train_coco.py --year year: For example, python3 train_coco.py --year 2014

If you want to train a model with both COCO datasets (training set = train2014 + val2014 + train2017, val set = val2017), you could run:

  • python3 train_coco_all.py

Test

For each type of dataset (VOC or COCO), I provide 3 different test scripts:

If you want to test a trained model with a standard VOC dataset, you could run:

  • python3 test_xxx_dataset.py --year year: For example, python3 test_coco_dataset.py --year 2014

If you want to test a model with some images, you could put them into the same folder, whose path is path/to/input/folder, then run:

  • python3 test_xxx_images.py --input path/to/input/folder --output path/to/output/folder: For example, python3 train_voc_images.py --input test_images --output test_images

If you want to test a model with a video, you could run :

  • python3 test_xxx_video.py --input path/to/input/file --output path/to/output/file: For example, python3 test_coco_video --input test_videos/input.mp4 --output test_videos/output.mp4

Experiments:

I trained models in 2 machines, one with NVIDIA TITAN X 12gb GPU and the other with NVIDIA quadro 6000 24gb GPU.

The training/test loss curves for each experiment are shown below:

  • VOC2007 voc2007 loss
  • VOC2012 voc2012 loss
  • COCO2014 coco2014 loss
  • COCO2014+2017 coco2014_2017 loss

Statistics for mAP will be updated soon ...

Results

Some output predictions for experiments for each dataset are shown below:

  • VOC2007

  • VOC2012

  • COCO2014

  • COCO2014+2017

yolo-v2-pytorch's People

Contributors

uvipen 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

yolo-v2-pytorch's Issues

pretrained yolo model

How can I get pretrained model? your linked addres is 404 unfowned. Please help me

What about TDD?

To keep your project stable across feature requests and commits, it's highly recommended to use a CI, for example: travis-ci.org.

In addition, the code coverage notation of your project shows the quality of the tests you've written.

confused with loss fuction

thanks to your great work, I learn a lot from your code, but when I use your code to train VOC2007 from scratch the confidence loss very large, so the total loss mostly control by confidence loss,I don't know how to fix it, can you give me some suggestions?

Result

Adding an analysis and elaborated explanation on the results for better understanding regarding the detection, accuracy and overall performance, would be quite helpful

deprecated Variable class

The test_coco_video.py code uses the Variable class, which is deprecated in recent versions of PyTorch. Instead, torch.tensor can be used directly.

  data = torch.tensor(image, dtype=torch.float32)

tensorboardX version problem

Please specify the tensorboardX version in ReadMe. The latest version is 1.7 now, and I think you use version 1.4. Using different version will cause errors.

Overfitting in the plots

Hi @vietnguyen91 , thanks for the great repo.

I was looking at the plots you have shown for the VOC training and I see a lot of overfitting in the test data. So, I was wondering why is that? Are you able to get good mAP eventually on the test data.

I am writing the code for yolo v2 myself in tensorflow and that's an issue I am really suffering from that my model is consistently overfitting just like yours and my output aren't as good as you have shown. I am using adam optimizer. I tried using SGD with momentum and weight decay as well as adam with weight decay but my network doesn't learn anything and the training oscillates without convergence. Have you seen anything of this sort?

Thanks for any suggestion or comments.
Best,
Saurabh

mAP

would you please provide
Statistics for mAP code

Save Model State Dictionary

When saving the model state dictionary, you use both torch.save(model, ...) and torch.save(model.state_dict(), ...). It's recommended to use the latter (state_dict()) for saving only the parameters, which is more memory-efficient. If you use torch.save(model, ...), it saves the entire model, including unnecessary information.

Distribution

A regular python project is consist of a mandatory setup.py file and optional: MANOFEST.in and setup.cfg files.

TOC in readme

You may use a lot of TOC generator tools to add a table of contents into the readme because your readme is too long.

Another option is to use Sphinx to document your project.

Deprecated manual_seed

In the train_coco.py code, the line torch.cuda.manual_seed(123) uses manual_seed, which is deprecated. Instead, you can use manual_seed_all.

   torch.cuda.manual_seed_all(123) if torch.cuda.is_available() else torch.manual_seed(123)

:TypeError forward() takes 2 positional arguments but 11 were given

runing train_voc.py
TypeError
forward() takes 2 positional arguments but 11 were given
File "G:\GitHub_work\Yolo-v2-pytorch\train_voc.py", line 95, in train
writer.add_graph(model.cpu(), torch.rand(opt.batch_size, 3, opt.image_size, opt.image_size))
File "G:\GitHub_work\Yolo-v2-pytorch\train_voc.py", line 186, in
train(opt)
help me ,please~~~~~~~ mang thanks

Training on 2014 + 2017 COCO doesn't make sense

Nice work with the repo. However, I noticed that you seemed to have combined the 2014 and 2017 data to train. However, if you read the COCO website carefully, you will find that the 2014 and 2017 data are identical (exactly the same number of total images). It's just that in 2017, they partitioned most of the images to be in train and only 5000 to be in the validation set.

If you train on 2014 train+val and 2017 train, you have essentially trained on the test data, so all metrics at that point are meaningless.

This is exactly the reason why your "test" set loss plots for 2014+2017 data show the test loss to continue to go down with epochs without ever entering a regime of being overtrained to your test dataset.

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.