GithubHelp home page GithubHelp logo

ruiminshen / yolo2-pytorch Goto Github PK

View Code? Open in Web Editor NEW
436.0 26.0 103.0 33.92 MB

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

License: GNU Lesser General Public License v3.0

Python 98.84% Shell 1.16%
yolo2 pytorch python object-detection deep-learning deep-neural-networks caffe2 onnx computer-vision

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  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)

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'

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 !

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.

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)

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)?

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.

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.

map

how about the map

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

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

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,

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.