Code Monkey home page Code Monkey logo

Comments (44)

ayooshkathuria avatar ayooshkathuria commented on August 25, 2024 2

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.

image

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

image.

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.

ayooshkathuria avatar ayooshkathuria commented on August 25, 2024

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.

ayooshkathuria avatar ayooshkathuria commented on August 25, 2024

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.

ayooshkathuria avatar ayooshkathuria commented on August 25, 2024

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.

zjcbatman avatar zjcbatman commented on August 25, 2024

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.

ayooshkathuria avatar ayooshkathuria commented on August 25, 2024

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.

zjcbatman avatar zjcbatman commented on August 25, 2024

000000

from yolo_v3_tutorial_from_scratch.

ayooshkathuria avatar ayooshkathuria commented on August 25, 2024

Thank you for pointing the flaw out. I'll try to look into it.

from yolo_v3_tutorial_from_scratch.

ayooshkathuria avatar ayooshkathuria commented on August 25, 2024

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.

zjcbatman avatar zjcbatman commented on August 25, 2024

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.

ayooshkathuria avatar ayooshkathuria commented on August 25, 2024

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)

image

confidence 0.25

from yolo_v3_tutorial_from_scratch.

ayooshkathuria avatar ayooshkathuria commented on August 25, 2024

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.

zjcbatman avatar zjcbatman commented on August 25, 2024

I also ran it on cpu. ok, thx.

from yolo_v3_tutorial_from_scratch.

ayooshkathuria avatar ayooshkathuria commented on August 25, 2024

HEY!!!!!!! LOOK AT THIS BEAUTY!

image

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.

zjcbatman avatar zjcbatman commented on August 25, 2024

oh, that's wonderful !

from yolo_v3_tutorial_from_scratch.

zjcbatman avatar zjcbatman commented on August 25, 2024

Have you found what's wrong with your NMS code?

from yolo_v3_tutorial_from_scratch.

ayooshkathuria avatar ayooshkathuria commented on August 25, 2024

Nope. Will look into that over the weekend.

from yolo_v3_tutorial_from_scratch.

zjcbatman avatar zjcbatman commented on August 25, 2024

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.

ayooshkathuria avatar ayooshkathuria commented on August 25, 2024

Does that solve the detection problem we were having?

from yolo_v3_tutorial_from_scratch.

zjcbatman avatar zjcbatman commented on August 25, 2024

det_000000
This is my final result

from yolo_v3_tutorial_from_scratch.

ayooshkathuria avatar ayooshkathuria commented on August 25, 2024

Great. Can you elaborate more on the error?

from yolo_v3_tutorial_from_scratch.

zjcbatman avatar zjcbatman commented on August 25, 2024

But I found that there are still some problems about this issue.
det_000003
predictions
and i commented the NMS code, got this
det_000003
so now there is nothing wrong with NMS, any other problem?

from yolo_v3_tutorial_from_scratch.

zjcbatman avatar zjcbatman commented on August 25, 2024

000003
this is the original pic

from yolo_v3_tutorial_from_scratch.

ayooshkathuria avatar ayooshkathuria commented on August 25, 2024

How did you go about removing the NMS code, what parts did you comment?

from yolo_v3_tutorial_from_scratch.

ayooshkathuria avatar ayooshkathuria commented on August 25, 2024

NMS code commented with your fix.

image

from yolo_v3_tutorial_from_scratch.

ayooshkathuria avatar ayooshkathuria commented on August 25, 2024

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.

zjcbatman avatar zjcbatman commented on August 25, 2024

(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.

zjcbatman avatar zjcbatman commented on August 25, 2024

image
the original pic of this is the first one i gave or the second?

from yolo_v3_tutorial_from_scratch.

zjcbatman avatar zjcbatman commented on August 25, 2024

shot
i have commented this for loop

from yolo_v3_tutorial_from_scratch.

zjcbatman avatar zjcbatman commented on August 25, 2024

I'd like to make my problem clear. NMS problem was solved. But I tested the code on another picture
000003
and i still got different results as follows:
det_000003
predictions
So i think there may be some other problem about this

from yolo_v3_tutorial_from_scratch.

ayooshkathuria avatar ayooshkathuria commented on August 25, 2024

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.

ayooshkathuria avatar ayooshkathuria commented on August 25, 2024

image
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.

ayooshkathuria avatar ayooshkathuria commented on August 25, 2024

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.

zjcbatman avatar zjcbatman commented on August 25, 2024

Oh, I just can't understand why the resolution could affect the result.

from yolo_v3_tutorial_from_scratch.

zjcbatman avatar zjcbatman commented on August 25, 2024

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.

zjcbatman avatar zjcbatman commented on August 25, 2024

I got one obvious example.
000015
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:
predictions

from yolo_v3_tutorial_from_scratch.

ayooshkathuria avatar ayooshkathuria commented on August 25, 2024

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.

zjcbatman avatar zjcbatman commented on August 25, 2024

ok, I am looking forward to that

from yolo_v3_tutorial_from_scratch.

ayooshkathuria avatar ayooshkathuria commented on August 25, 2024

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.

zjcbatman avatar zjcbatman commented on August 25, 2024

Great! I think that will solve this issue! Thanks!

from yolo_v3_tutorial_from_scratch.

ayooshkathuria avatar ayooshkathuria commented on August 25, 2024

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.

zjcbatman avatar zjcbatman commented on August 25, 2024

I have tested on my dataset and I think this time the issue was totally solved !

from yolo_v3_tutorial_from_scratch.

ayooshkathuria avatar ayooshkathuria commented on August 25, 2024

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.

priyankasin avatar priyankasin commented on August 25, 2024

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)

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.