-
Notifications
You must be signed in to change notification settings - Fork 24
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
About yolo mask #2
Comments
The author of YOLOv3 also using
I just follow the setting of original code. Currently, we do not have plan to release Pelee-PRN. |
Well I can't see any clue of original author using
I checked out all the .cfg by pjreddie and AlexeyAB, and couldn't find them using duplicate anchors.
because you are finally using the (10,14) anchor, and the drawback may be a little drop on (81,82) one, but it's worth a try. |
@Libero-zz Hello, You can see the first commit of yolov3-tiny.cfg https://github.com/pjreddie/darknet/commits/master/cfg/yolov3-tiny.cfg The provided weight file of yolov3-tiny by author is trained using the mask = 1,2,3. |
Yeah, the author might make some mistakes |
For a fair comparison, I should use mask = 1,2,3 & mask = 3,4,5 in yolov3-tiny-PRN. For YOLOv3-PRN experiments, I use mask = 0,1,2 & mask = 3,4,5 & mask = 6,7,8. |
@WongKinYiu Okay but And I am not sure that the author's original results were with the buggy mask. Anyway thanks a lot for your research about PRN and design of this tiny yolo config! :-) |
well...as i think, it was a feature, not a bug. you can simply calculate the the grid size of second pyramid: 416/26=16. in my experiments, i have trained yolo-v3-tiny more than five times using both of |
Wow, really? Very interesting. How are the results better? (Better mAP%? Faster network?) Are you doing full training from empty weights, when you compared mask012 vs mask123? (This would matter because if you reuse weights trained with 123, it would obviously be biased for 123). PS: This is weird because |
better mAP. also, u can find the results of yolo-v3-tiny on your posted link. i trained the models from imagenet pretrained weight. yes, the paper says "our system only assigns one bounding box prior for each ground truth object", |
Ohh okay! For any future readers, we're talking in two tickets at the same time now... and here's the thing WongKinYiu is referring to: AlexeyAB/darknet#3380 (comment) So the yolo-v3-tiny (official) results are bad because the weights were trained with
Ah yes the YOLO paper confirms that
Okay so you used transfer learning. My worry is that if you have a pretrained weight made with 123, and you transfer learn it to a 012 "fixed" net, you still have some bias towards 123 which means 123 would get better mAP... So the final question I have is: Which imagenet pretrained weight did you use? The @pjreddie file with mask=123, or did you train your own "prn" imagenet weights from empty weights first? Because I am super interested in knowing what YOLOv3-Tiny-PRN's mAP performance is with mask=0,1,2 with imagenet weights trained with mask=0,1,2 too. Maybe the accuracy goes up even more when the "mask bug" is "fixed"?! ;-) |
we need not to re-train imagenet for different mask setting. you can follow https://github.com/AlexeyAB/darknet#how-to-train-tiny-yolo-to-detect-your-custom-objects |
@WongKinYiu Yeah we don't "need" to retrain it and we can still load the same weights with different mask settings... But doesn't the mAP go down if we re-use old weights that were trained with a different mask? Because those weights are tuned to provide neural network outputs that give good mAP results with the originally trained mask, and very bad results if you change the cfg. Exactly as you showed me... the Tiny-v3 bounding boxes became wrong in that video we looked at when a different mask So all I am saying is: If we change Here's my theory/understanding so far:
Right now we only have weights files trained with What do you think? Or is my understanding here wrong? |
these are correct, but we need to fully re-train COCO, not ImageNet. |
@WongKinYiu Ohhhh, okay, really sorry for mixing up the words ImageNet and COCO, I forgot that your model weights were trained on COCO (with transfer learning from the But yeah, all of this makes me wonder if fully re-training the COCO weights with |
Okay according to @pjreddie the The lower mask numbers are the smallest objects. So the answer is: If we fix |
Okay, we just had a conversation in a different thread and it emerged that you've already trained COCO on both 012 and 123: #7 (comment) I would have to check the darknet source code, to know for sure, but... the 123 mask has two problems:
Alright so with that technical stuff explained... if you're getting better mAP by losing the 0th anchor (smallest items), perhaps that means that YOLO is IMPROVED by removing that anchor... |
Parses mask=... cfg text into an array of integers: https://github.com/AlexeyAB/darknet/blob/master/src/parser.c#L318-L337 Creates a yolo layer with mask param set to those masks: https://github.com/AlexeyAB/darknet/blob/master/src/yolo_layer.c#L13 The rest of yolo_layer.c seems to use the mask value to load the So my earlier guess was wrong. The layers do not overwrite each others maskresult. They simply load the same anchor (bias). No overwriting as far as I can see. Each YOLO layer has its own independent array-copy of the anchor integers and mask integers. So, what a cfg with "mask = 123 and mask = 345" does is simply this:
So if my incomplete analysis of the code is correct, there is no problem reusing mask except that you lose the smallest object size detections. (You lose the smallest anchor size completely). And instead, you reuse anchor mask 3 "medium size object" twice, in both YOLO layers. It's very possible that this improves accuracy because it lets both layers detect medium size object. So perhaps this actually optimizes the network for average-sizd objects (but it loses small objects, but maybe they don't matter)... |
If this code analysis is correct, both of these configs are identical: A:
B:
|
Yes I found the missing puzzle piece now: https://github.com/AlexeyAB/darknet/blob/master/src/parser.c#L376-L389 Parser.c translates And translates So yes these configs are identical: What do you think about that @WongKinYiu? You've discovered a way to increase mAP by ignoring the smallest anchor and reusing the medium-size anchor. So perhaps this should be proposed to @AlexeyAB as a better way to calculate anchors (in darknets "calculate anchors" mode). But probably with a slightly better medium-box (instead of reusing the same box twice). The first yolo layer should probably have a box between the sizes of box 2 and box 3. — PS: The process can probably be automated by telling darknet "calculate anchors" mode to generate 7 anchors, then deleting the smallest anchor so you have 6 anchors. Then setting first layer to It will probably improve mAP even more, because the layers will have more detailed anchor boxes to use. |
@WongKinYiu Here's a
Behavior is identical, anchors are identical, but now the mask values are proper. |
It is just a bug in pjreddie repo. It doesn't increase accuracy.
|
@VideoPlayerCode Hello, we should not for for
we do not need to adjust smallest anchor for this case. the conclusion is that we should adjust and reassign anchors to proper grid scale.
|
Hello @AlexeyAB, thanks for answering in this topic.
That's what @WongKinYiu said though. Here: #7 (comment) "however, for coco dataset, i use same imagenet pre-trained model, mask = 1,2,3 get better mAP than mask = 0,1,2." He said he trained TWO models,
That's what I thought too, but in the link above he claims it gives better mAP period, even when he tried a
Yes it is a bug. @WongKinYiu Hello again. :-) You said "we should not remove smallest anchor without reason." but this patch (#2 (comment)) was just meant to show you that by setting mask=1,2,3 your config already removes the smallest anchor. My patch anchors are 100% the same as the cfg you released. Because your config does not use anchor 0 at all. So I just edited the anchors to fix Btw, what you're showing above sounds interesting. Is that some new ideas for optimizing anchors, that can be put into darknet's |
I tried to use overlapped anchors int this model mask = 0,1,2,3,4 |
@AlexeyAB Yep overlapping anchors is valid since the mask just controls which anchor sizes the layer will try. But the problem here is different; that @WongKinYiu said that by deleting (not using) the smallest anchor, mAP increases. |
Why are you using
instead of
Besides, is there any plan of releasing Pelee-PRN?
Thanks for the great work.
The text was updated successfully, but these errors were encountered: