Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with YOLOv3 Anchors on Scale #167

Open
ljbkusters opened this issue Nov 15, 2023 · 2 comments
Open

Issue with YOLOv3 Anchors on Scale #167

ljbkusters opened this issue Nov 15, 2023 · 2 comments

Comments

@ljbkusters
Copy link

Hi there, I've really enjoyed following your tutorial on implementing the YOLOv3 algorithm. I've been testing my own YOLOv3 model built from scratch (to work with 1D data inputs and 1D convolutions, so technically speaking not a typical YOLOv3 model). Please note that I'm also using my own dataset of 1D arrays I generated. I have noticed the following during testing:

When removing the has_anchor[scale_idx] check (line 73 of dataset.py) I seem to get predictions with much higher confidence and a higher recall overall. I also seem to be getting a lot fewer false positives (mainly wrong classifications on an object that already has been classified with the correct class). I've noticed that in the README you under the heading "Things I'm unsure of" you discuss exactly this feature of the target selection at various scales, and you seem unsure how this affects prediction quality.

I've had a look at the Ultralytics implementation of target assignment (they assign targets at loss calculation, not during dataset loading). They do loop over the anchors and select the best matching target I believe, but they do not check based on if every scale has one anchor. I'm not 100% sure on this because their implementation is quite dense and somewhat unreadable, but this supports my hunch that this check is superfluous and may impact learning.

For me this makes some sense intuitively however, since by forcing targets onto all scales, you might choose sub-optimal anchor boxes, which in the loss calculation step lowers the IOU and thereby impedes loss minimization towards objectness (as this is weighted by the IOU in your implementation).

Let me be clear that I'm not sure if this is true generally, I've not tested it on the VOC or MS COCO datasets using your repo, but it might be worth looking into to see if it affects performance! You, or anyone implementing your code for themselves, might want to test to see if it helps improve their training results.

@peduajo
Copy link

peduajo commented Dec 4, 2023

Several months ago thanks to this video I tried to implement Yolov3 for the PascalVOC 2012+2007 dataset but I have not been able to get it to converge to an acceptable MAP. Also, that it has very poorly optimized functions like NMS. I think the implementation has problems in addition to not converging well because of gradient instability issues. If anyone has a correct implementation of the code it would be helpful if you could share it.

@ljbkusters
Copy link
Author

@peduajo have a look at my repo https://github.com/ljbkusters/YOLOv3-1D. It implements the network to work with 1D convolutions but the main structure remains the same. Specifically regarding the issue I have described above, have a look at the dataset target creation code. Here I removed the "one anchor per scale" constraint, which I haven't seen implemented in the Ultralytics repo.

NMS can definitely be optimized as well using pure PyTorch instead of loops and lists. I managed to optimize it a little, although I can't share that code. It's sereously not that complicated though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants