Giter VIP home page Giter VIP logo

yolo2-pytorch's Introduction

PyTorch implementation of the YOLO (You Only Look Once) v2

The YOLOv2 is one of the most popular one-stage object detector. This project adopts PyTorch as the developing framework to increase productivity, and utilize ONNX to convert models into Caffe 2 to benefit engineering deployment. If you are benefited from this project, a donation will be appreciated (via PayPal, 微信支付 or 支付宝).

Designs

  • Flexible configuration design. Program settings are configurable and can be modified (via configure file overlaping (-c/--config option) or command editing (-m/--modify option)) using command line argument.

  • Monitoring via TensorBoard. Such as the loss values and the debugging images (such as IoU heatmap, ground truth and predict bounding boxes).

  • Parallel model training design. Different models are saved into different directories so that can be trained simultaneously.

  • Using a NoSQL database to store evaluation results with multiple dimension of information. This design is useful when analyzing a large amount of experiment results.

  • Time-based output design. Running information (such as the model, the summaries (produced by TensorBoard), and the evaluation results) are saved periodically via a predefined time.

  • Checkpoint management. Several latest checkpoint files (.pth) are preserved in the model directory and the older ones are deleted.

  • NaN debug. When a NaN loss is detected, the running environment (data batch) and the model will be exported to analyze the reason.

  • Unified data cache design. Various dataset are converted into a unified data cache via corresponding cache plugins. Some plugins are already implemented. Such as PASCAL VOC and MS COCO.

  • Arbitrarily replaceable model plugin design. The main deep neural network (DNN) can be easily replaced via configuration settings. Multiple models are already provided. Such as Darknet, ResNet, Inception v3 and v4, MobileNet and DenseNet.

  • Extendable data preprocess plugin design. The original images (in different sizes) and labels are processed via a sequence of operations to form a training batch (images with the same size, and bounding boxes list are padded). Multiple preprocess plugins are already implemented. Such as augmentation operators to process images and labels (such as random rotate and random flip) simultaneously, operators to resize both images and labels into a fixed size in a batch (such as random crop), and operators to augment images without labels (such as random blur, random saturation and random brightness).

Feautures

  • Reproduce the original paper's training results.
  • Multi-scale training.
  • Dimension cluster.
  • Darknet model file (.weights) parser.
  • Detection from image and camera.
  • Processing Video file.
  • Multi-GPU supporting.
  • Distributed training.
  • Focal loss.
  • Channel-wise model parameter analyzer.
  • Automatically change the number of channels.
  • Receptive field analyzer.

Quick Start

This project uses Python 3. To install the dependent libraries, type the following command in a terminal.

sudo pip3 install -r requirements.txt

quick_start.sh contains the examples to perform detection and evaluation. Run this script. Multiple datasets and models (the original Darknet's format, will be converted into PyTorch's format) will be downloaded (aria2 is required). These datasets are cached into different data profiles, and the models are evaluated over the cached data. The models are used to detect objects in an example image, and the detection results will be shown.

License

This project is released as the open source software with the GNU Lesser General Public License version 3 (LGPL v3).

yolo2-pytorch's People

Contributors

minimumshen avatar ruiminshen avatar ss18 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

yolo2-pytorch's Issues

Question on yolo backward function

Hi there, sorry about that to post this here, i was trying to write yolo in torch but struggled the backward function for so many days, but the gradients are always exploding slowly, could you kindly shed a light on my codes? Thank you so much.

gradInput[{ {}, {}, 1, {}, {} }] = self.mse:backward(torch.cmul(self.x_buffer, x, coord_mask), tx)
gradInput[{ {}, {}, 2, {}, {} }] = self.mse:backward(torch.cmul(self.y_buffer, y, coord_mask), ty)
gradInput[{ {}, {}, 3, {}, {} }] = self.mse:backward(torch.cmul(self.w_buffer, w, coord_mask), tw)
gradInput[{ {}, {}, 4, {}, {} }] = self.mse:backward(torch.cmul(self.h_buffer, h, coord_mask), th)
gradInput[{ {}, {}, 5, {}, {} }] = self.mse:backward(torch.cmul(self.conf_buffer, conf, coord_mask), tconf)
gradInput[{ {}, {}, { 6, 5 + nC }, {}, {} }][self.cls_mask] = self.ce:backward(torch.cmul(self.cls_buffer, cls), tcls)

train with mobilenet

Is the following script correct to train yolo2 with mobilenet?

python3 train.py -b 64 -lr 1e-3 -e 160 -m cache/name=cache_voc model/name=model_voc model/dnn=model.mobilenet.MobileNet train/optimizer='lambda params, lr: torch.optim.SGD(params, lr, momentum=0.9)' train/scheduler='lambda optimizer: torch.optim.lr_scheduler.MultiStepLR(optimizer, milestones=[60, 90], gamma=0.1)' -d

Thanks,

Caffe2 Deployment

Great work on this setup.

We can export the weights to Caffe2, but then how do we utilize the deployed weights in a Caffe2 instance on something like an nVidia Jetson TX2? There's no real Yolo2 for Caffe2, right?

I'm confused as to why you're converting to Caffe2 and how that deployment would actually work.

Error when convert darknet model to torch too

I can't convert proper file by using your convert_darknet_torch.py .
And I met the same error as #8
Could u please upload the right file darknet19_448.conv.23.pth or just fix the bug ?
million thanks !

Train with GTX 1080 and Anchor Boexes

Hi ,
Q1) Anchor_Boxes_Generator file generate 10 values of anchors , i have question about these values , as we have 5 anchors and this generator generate 10 values, more likely a first two of 10 values related to first anchor box , right ? if so , what are means of these two values ? W , H for first anchors for aspect ratio and scale for that anchor?
Q2) Is it possible to fine-tuning this with one GTX 1080 (8G)?

Good job

I think you have done a good job,but I read your readme,I can't understand what the function of your every py file,can you explain how to detect,eval sepretely instead of have them in a sh file

ImportError: cannot import name 'pystone' help

Traceback (most recent call last):
File "detect.py", line 27, in
import pybenchmark
File "/home/a/anaconda3/lib/python3.6/site-packages/pybenchmark/init.py", line 1, in
from .profile import profile, stats, kpystones, pystones
File "/home/a/anaconda3/lib/python3.6/site-packages/pybenchmark/profile.py", line 3, in
from test import pystone # native python-core "PYSTONE" Benchmark Program
ImportError: cannot import name 'pystone'

cache.py not enough values to unpack (expected 2, got 1)

INFO:root:load voc dataset
Traceback (most recent call last):
File "cache.py", line 70, in
main()
File "cache.py", line 50, in main
module, func = dataset.rsplit('.', 1)
ValueError: not enough values to unpack (expected 2, got 1)

Several issues about reproducing darknet results

  1. Converting darknet weights to torch
    The header of darknet weights includes 4 numbers,“major, minor, revision, seen”. The type of “seen” is “size_t” , while the others are “int”. On my system, “size_t” is 8 byte, instead of 4. This may due to the attributes of the compiler. But in my case, your code gives warning as “4 bytes left”.
    If I change
    major, minor, revision, seen = struct.unpack('4i', f.read(16))
    to
    major, minor, revision = struct.unpack('3i', f.read(12))
    seen = struct.unpack('Q', f.read(8))[0]
    It would be fine.

  2. The order of region layer channels.
    In darknet, the order of region layer channels is “x, y, w, h, iou, probs”. In your implementation, it seems to be “iou, y, x, h, w, probs”.
    I think you already noticed the problem of “iou” channel. In “convert_darknet_torch.py”, you use “transpose_weight” and “transpose_bias” to switch the order of the weights. But it would be unnecessary if you change the region layer as
    iou = F.sigmoid(_feature[:, :, :, 4])
    Due to the inconsistent order between “y, x, h, w” and “x,y,w,h”, I also have to use the following order to reproducing the results of darknet
    center_offset = F.sigmoid(_feature[:, :, :, [1,0]])
    size_norm = _feature[:, :, :, [3,2]]
    The other way is to change all the “yx_min”, “yx_max” to “xy_min”, “xy_max”, and do something about the post processing. But it needs much more work.

  3. Reproducing the darknet training results (unsolved)
    I still cannot reproduce the darknet training results on my own data using your code. I think the loss is kind of weird, but I have not find the problem.
    I tried several implement of YOLO by tensorflow or pytorch. None of them can reproduce the magic training result of darknet. Your implement seems to be the most promising one. I really appreciate your work and hope you can make it better.

map

how about the map

Error when convert darknet model to torch

When convert the darknet yolo-voc weight to torch model, error occurs like this:

Traceback (most recent call last):
  File "convert_darknet_torch.py", line 140, in <module>
    main()
  File "convert_darknet_torch.py", line 105, in main
    val = np.array(struct.unpack('%df' % cnt, f.read(cnt * 4)), np.float32)
struct.error: unpack requires a bytes object of length 4096

Because I only want to obtain a torch model and evaluate it by myself, I didn't run quick_start.sh to do dataset caching. The main steps are as following:

First, I downloaded weight file from website of darknet and put it in $ROOT, which is $HOME/model/darknet:

wget http://pjreddie.com/media/files/darknet19_448.conv.23

And the command I used to convert the model is (just copied from the quick_start.sh script):

python3 convert_darknet_torch.py ~/model/darknet/darknet19_448.conv.23 -m model/name=model_voc model/dnn=model.yolo2.Darknet -d --copy ~/model/darknet/darknet19_448.conv.23.pth

And could you tell me the difference of darknet19_448.conv.23 and yolo-voc.weights? I tried to convert yolo-voc.weights and it worked well.

Error happened when convert pretrained darknet model

When I convert pretrained darknet model with this command:

python3 convert_darknet_torch.py ~/model/darknet/darknet19_448.conv.23 -m model/name=model_voc model/dnn=model.yolo2.Darknet -d --copy ~/model/darknet/darknet19_448.conv.23.pth

error happened:

Traceback (most recent call last):
File "convert_darknet_torch.py", line 142, in
main()
File "convert_darknet_torch.py", line 107, in main
val = np.array(struct.unpack('%df' % cnt, f.read(cnt * 4)), np.float32)
struct.error: unpack requires a bytes object of length 4096

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.