ruiminshen / yolo2-pytorch Goto Github PK
View Code? Open in Web Editor NEWPyTorch implementation of the YOLO (You Only Look Once) v2
License: GNU Lesser General Public License v3.0
PyTorch implementation of the YOLO (You Only Look Once) v2
License: GNU Lesser General Public License v3.0
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)
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'
skimage=0.0
这个写错了吧。。。。
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 !
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.
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.
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.
I have got the densenet201_yolo.cfg and the .weights file. How to do image detection on Pytorch??
Thanks!!
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)
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)?
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.
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.
how about the map
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
Dear @ruiminshen,
The new version of YOLO has been released (i.e., YOLOv3).
Can I use YOLOv3 cfg/weights with your code correctly?
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
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,
when i ran quick_start.sh,it show some warning.
WARNING - training config (pre_model/yolo2-pytorch/model_20/model.yolo2.Darknet.ini) not found
And i can't found model.yolo2.Darknet.ini in project.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.