Comments (44)
So, I finally got the error, I think. The fix works on all of the images you have provided. This is the intermediate result (I wrote custom code to test my solution) for the last image that you have provided.
The problem
So, looking at darknet I realized that the way an input image is resized to 416 x 416 is different from what I was doing. In darknet, the image is resized keeping the aspect ratio intact, and padding the remaining area. For example, when your image, being resized to 416 x 416 will look like this
I had simply resized it isotropically using cv2.resize
and writing a function that does something like above did solve the issue. I'll be integrated changes into the repo in the next day or two. Currently, the bounding box drawing code is written in accordance with isotropic resizing and I'll have to change that, and will push the fix to the repo soon.
from yolo_v3_tutorial_from_scratch.
Beat me too. Honestly, even for the other repos of YOLO v2 I had come across, they couldn't match the accuracy of darknet, (the mAP was 76.8 using exactly the same cfg and weights file, whereas it was 78.6 with the original darknet). I haven't dwelt too much into the issue. Even while training from scratch they couldn't achieve more than 75 mAP.
I have used billinear umpsampling in the upsample layer. Maybe the original repo has something else. Maybe nearest neighbour sampling. So, you can find the code responsible for that in the function create_modules
in util.py.
Also, you can try to decrease the objectness_confidence threshold. from 0.5 to something like 0.3.
from yolo_v3_tutorial_from_scratch.
Another culprit I think might be the way GCC (original darknet compiler) and python handle floats. I think things get screwed up in floating precision rounding off or something. Otherwise there's no freaking way an identical set of operations produce a different result. I'm gonna try different forms of upsampling over the weekend if that's what is causing the issue.
from yolo_v3_tutorial_from_scratch.
My C skills really up to the mark where I can tear apart darknet, this has been on my list for a long time, but I've always been too busy to learn some quality C.
from yolo_v3_tutorial_from_scratch.
I have decreased the confidence to 0.25 right now because i have seen the original darknet is 0.25, but i still got the same result
from yolo_v3_tutorial_from_scratch.
Can you send me the pic. I'll just try looking at the output feature map and inspect the values over at the weekend. Just upload it in a comment here.
from yolo_v3_tutorial_from_scratch.
from yolo_v3_tutorial_from_scratch.
Thank you for pointing the flaw out. I'll try to look into it.
from yolo_v3_tutorial_from_scratch.
Could you think of a reason why this might be happening? Do you think if it's a pytorch thing. Maybe some way darknet is different from pytorch?
from yolo_v3_tutorial_from_scratch.
My pleasure. I think it's great to translate the darknet into pytorch. I have not got any idea about this issue now. I will look into your code and darknet to see whether there is some difference
from yolo_v3_tutorial_from_scratch.
Weird stuff. This is the result on my mac, (I ran it on CPU since I don't have access to a GPU at home)
confidence 0.25
from yolo_v3_tutorial_from_scratch.
Please check how upsampling is done in darknet for sure, coz that's what i think may be the weak link.
from yolo_v3_tutorial_from_scratch.
I also ran it on cpu. ok, thx.
from yolo_v3_tutorial_from_scratch.
HEY!!!!!!! LOOK AT THIS BEAUTY!
I commented out the NMS code. So, it means, I've screwed up somewhere in NMS code and that problem didn't show it's head until your example came. Thank you man (or woman?)
I'll try to solve it as soon as possible.
from yolo_v3_tutorial_from_scratch.
oh, that's wonderful !
from yolo_v3_tutorial_from_scratch.
Have you found what's wrong with your NMS code?
from yolo_v3_tutorial_from_scratch.
Nope. Will look into that over the weekend.
from yolo_v3_tutorial_from_scratch.
hi, I have found your small mistake. In the function bbox_iou in util.py,
inter_area = (inter_rect_x2 - inter_rect_x1 + 1) * (inter_rect_y2 - inter_rect_y1 + 1)
you have forgot that either two may smaller than 0, i think you should change this to
w = np.maximum(inter_rect_x2 - inter_rect_x1 + 1, 0) h = np.maximum(inter_rect_y2 - inter_rect_y1 + 1, 0) inter_area = w * h
from yolo_v3_tutorial_from_scratch.
Does that solve the detection problem we were having?
from yolo_v3_tutorial_from_scratch.
from yolo_v3_tutorial_from_scratch.
Great. Can you elaborate more on the error?
from yolo_v3_tutorial_from_scratch.
But I found that there are still some problems about this issue.
and i commented the NMS code, got this
so now there is nothing wrong with NMS, any other problem?
from yolo_v3_tutorial_from_scratch.
from yolo_v3_tutorial_from_scratch.
How did you go about removing the NMS code, what parts did you comment?
from yolo_v3_tutorial_from_scratch.
NMS code commented with your fix.
from yolo_v3_tutorial_from_scratch.
I'm just wondering which of the run cases causes the negative value of the line (inter_rect_x2 - inter_rect_x1 + 1)
cause that seems to be the problem!!!
from yolo_v3_tutorial_from_scratch.
(inter_rect_x2 - inter_rect_x1 + 1)<0 and (inter_rect_y2 - inter_rect_y1 + 1)<0, so inter_area > 0
this may happen when two different bboxes with two different targets but they are in the same class,
you can imagine two planes in this picture, and you also have two bboxes with these two different planes.Abviously, there is no intersection with these two bboxes,but in your code, you may get inter_area > 0
from yolo_v3_tutorial_from_scratch.
the original pic of this is the first one i gave or the second?
from yolo_v3_tutorial_from_scratch.
i have commented this for loop
from yolo_v3_tutorial_from_scratch.
I'd like to make my problem clear. NMS problem was solved. But I tested the code on another picture
and i still got different results as follows:
So i think there may be some other problem about this
from yolo_v3_tutorial_from_scratch.
Yes, I get the same thing in the second pic. Hmm. I will look into the matter tomorrow now. Perhaps a good night's sleep will help me find the issue :P
from yolo_v3_tutorial_from_scratch.
This is the result for your second image, everything is the same. Except I changed the input resolution to 608 instead of 416, which was default in my code. You can do that by --reso
flag with detect.py
from yolo_v3_tutorial_from_scratch.
It's a bit crazy I can register all detections at 0.5 confidence at 448 resolution, but miss 3 when I switch the resolution to 416, the native resolution.
But hey, look at this, https://groups.google.com/forum/#!topic/darknet/JTNuaTtpm94, where joseph redmon, originally talks about how implementation of YOLO is CPU is different. Maybe the optimisations introduced by PyTorch are pushing the scores of the three missed planes to zero.
I'd compare the results on Monday on a GPU to get a more realistic estimate of how similar the performances are.
from yolo_v3_tutorial_from_scratch.
Oh, I just can't understand why the resolution could affect the result.
from yolo_v3_tutorial_from_scratch.
Personally, I think changing the input resolution did not solve this problem totally, because I tested the code on another image after changing the resolution to 448, the same different results happened
from yolo_v3_tutorial_from_scratch.
I got one obvious example.
I tested the code on this pic, but the result was no plane is on this pic no matter what the input resolution is. I tested 448 and 608 resolution.
However, in the original darknet, I got this:
from yolo_v3_tutorial_from_scratch.
Ok, I will try to write a script that compares a value of output of each layer in darknet, and my code and compares it, and then figure out where the issue lies (by finding the first point of difference). This might take a bit time coz I'm not as fluent with C as I am with Python, but now, I'm determined to solve this :)
from yolo_v3_tutorial_from_scratch.
ok, I am looking forward to that
from yolo_v3_tutorial_from_scratch.
I tried to run the code on a GPU, and the problem persists. This means the issue is with my implementation and not the optimizations done by the underlying libraries.
from yolo_v3_tutorial_from_scratch.
Great! I think that will solve this issue! Thanks!
from yolo_v3_tutorial_from_scratch.
I have pushed the changes. Please check whether your issues were resolved or not. And yes, the code will work only with PyTorch 0.4, which is available on pip and conda channels now.
from yolo_v3_tutorial_from_scratch.
I have tested on my dataset and I think this time the issue was totally solved !
from yolo_v3_tutorial_from_scratch.
All right. I'm closing this issue then. Thanks for your time in pointing out and helping solve this issue.
from yolo_v3_tutorial_from_scratch.
I have run your code and darknet_alexey with the same images and same weights but I got different results. Earlier you had the same issue and you resolve this issue, but I still got the error with your updated repo. can you please help me to resolve the issue?
from yolo_v3_tutorial_from_scratch.
Related Issues (20)
- In function prep_image
- What is loading batch?
- yolov3-tiny model image dimensions error
- how to run detect.py
- google colab
- testing object detector
- bounding boxes not correct HOT 1
- How to solve this runtime error problem? HOT 1
- darknet spp maxpool
- 'NoneType' object has no attribute 'shape' HOT 1
- cv2.imwrite doesn't output image HOT 1
- the problem of function "predict_transform" HOT 1
- Why does batch norm layer has the parameter of weight and bias? HOT 2
- Why do we reverse the final dim of the image in "prep_image"? HOT 1
- Quick question
- RuntimeError: Expected object of device type cuda but got device type cpu for argument #1 'self' in call to _thnn_conv2d_forward
- OpenCV(4.5.2) :-1: error: (-5:Bad argument) in function 'rectangle' HOT 4
- Anchors scaling for each feature map output HOT 1
- Object detection algorithms
- why no images saved in the directory named 'det' HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yolo_v3_tutorial_from_scratch.