-
-
Notifications
You must be signed in to change notification settings - Fork 16.4k
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
How to add another detection head ? #1418
Comments
@Edwardmark design modifications are up to you. Start from the existing yamls and modify as you see fit. |
@Edwardmark Have you solve the problem ? I also want to add and modify the detection head. And now I can't find the location of the detection head 's code |
@glenn-jocher Could you please explain the parameters in yolov5l.yaml a little, let's say, if we want to add a head which aims to detect large objects (e.g. 640x640 big objects), what should be added to anchor and backbone and head in yolov5l.yaml? |
@Edwardmark @JoJoliking sure no problem. The current models output P3-P5 layers supporting strides 8-32. You want to export a P6 layer with stride 64. You can export from any layer of the model you want simply by adding it to the input list of Detect(). This is one of the major advancements we made in YOLOv5 above and beyond the previous cfg architectures: Line 47 in 199c9c7
So all you need to do is build the additional structure you want and then add the output layer you want to this list. You could then add another set of P6/64 anchors manually to the model, or you could simply delete the manual anchors and put a number instead, like Lines 7 to 11 in 199c9c7
To build the additional structure, you can simply repeat the steps from P4 to P5: Lines 38 to 47 in 199c9c7
In terms of P6, there's no 64-stride layers earlier to concat, so you could simply do something like this for the easiest P6/64 output. If you wanted to get fancier you could have the backbone travel down to P6/64, and then concat that layer with the head (same as P5 is handled). [-1, 1, Conv, [256, 3, 2]],
[[-1, 14], 1, Concat, [1]], # cat head P4
[-1, 3, BottleneckCSP, [512, False]], # 20 (P4/16-medium)
[-1, 1, Conv, [512, 3, 2]],
[[-1, 10], 1, Concat, [1]], # cat head P5
[-1, 3, BottleneckCSP, [1024, False]], # 23 (P5/32-large)
[-1, 1, Conv, [1024, 3, 2]],
[-1, 3, BottleneckCSP, [2048, False]], # 25 (P6/64-xlarge)
[[17, 20, 23, 25], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5, P6) |
By the way, you should be aware that P6 outputs will mainly benefit larger image sizes. So you are travelling down a road of a larger models applied to larger images (i.e. longer training, more CUDA memory usage, etc.). If you wanted to go the other way and create models that work better on smaller images you might output a P2/4 (stride 4) layer instead. P2 output layers incur minimal size increases, but many more FLOPS as the convolutions are applied over larger denser grids, slowing inference significantly. |
@glenn-jocher Excellent answer. |
@JoJoliking the four YOLOv5 models s/m/l/x are all built from yolov5-panet.yaml with different compound scaling constants. I experimented to find the best constants ratio, starting from the EfficientDet scaling equations, and these are used now for the four sizes. FPN heads (like in YOLOv3) perform worse and are no longer used, though yolov5-fpn.yaml is archived for historical reasons (and to show how to modify the head structure from FPN to PANet). |
Also common.py and experimental.py define low level modules that are used to create FPN or PANet heads. The heads themselves are only created and defined in the yamls. |
@glenn-jocher All right。 I already know the relationship between the network structure。 |
@JoJoliking I don't understand what you are asking. |
@glenn-jocher |
The three n-to-255 convolutions are contained inside the Detect() layer, you can apply any modifications you want there. Though applying offsets/gains to the existing offsets and gains may overdetermine some of the parameters. ie fitting two offsets for one value is not typical in parameter estimation as there is only 1 degree of freedom there. |
@glenn-jocher Thanks for your kind reply. It helps me a lot. |
Hello, I would like to ask me to add some anchor box parameters after the anchor attribute in yolov5s.yaml, but an overflow error will be displayed. Excuse me, is this not allowed? Or is there anything I haven’t changed? The parameters I added are like this.
|
@mary-0830 you're free to modify anchors as you see fit. The only constraint is each output layer requires the same number of anchors. If autoanchor doesn't like your new anchors, it will create new ones on it's own, based on the number you supplied initially. You can disable autoanchor with python train.py --noautoanchor. You can also simply specify a number here instead of anchor vectors: |
@glenn-jocher If I add head, what shold I modified in the compute_loss funcition? How to set balance? in compute_loss function? |
@Edwardmark modifications are up to you. |
@glenn-jocher Hallow, If I want to load multiple data sets for training at the same time (they will be placed in the same subfolder), then how should I modify the LoadImagesAndLabels function? |
@JoJoliking coco128.yaml already explains how to load multiple datasets. Do not modify the code. Lines 12 to 15 in 97a5227
|
OK .I will have a try. Thank you for your previous reply to my question. I have a success. |
@glenn-jocher |
@JoJoliking I would recommend training with all default settings (no modification). To start see: |
@glenn-jocher OK. Thanks .I will try my ideas. |
@JoJoliking ok! Also remember COCO models already offer human detection. You can also filter detections by class to only show human detections like this, so in reality I would not even train a new model if all you want is human detection: python detect.py --classes 0 |
@glenn-jocher |
@JoJoliking yes, this is normal. Single-class datasets do not have any classification loss as there is no classification task, only objectness loss. |
Hello author, I want to add a detection layer for detecting small targets. Now the latest code has been modified, how should I modify it@glenn-jocher anchorsanchors:
YOLOv5 backbonebackbone: [from, number, module, args][[-1, 1, Focus, [64, 3]], # 0-P1/2 YOLOv5 headhead: [-1, 1, Conv, [256, 1, 1]], [-1, 1, Conv, [256, 3, 2]], [-1, 1, Conv, [512, 3, 2]], [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) |
@WANGCHAO1996 YOLOv5-p2 adds an extra small detection head (P2, stride 4): |
Should this line yolov5/models/hub/yolov5-p2.yaml Line 53 in b894e69
add 21 to the anchor list? Besides, maybe the |
@YukunXia actually yes, maybe the Detect input list should probably include 21 as well. You can train either way, with the current setup using the same output strides, but with the PANet head dipping down into P2 stride convolutions to help add accuracy to the P3 output. It's been a while since I made this so I can't remember if the 21 omission is intentional or not. Can you submit a PR with the 21 addition to this yaml? Thanks! |
OK, the PR is submitted. |
@glenn-jocher Dear Author. By the way. Have you tried to use BiFPN in Yolov5 instead of PANet ? My experiments show that BiFPN with stacking 3 Layers can reach a better map on other datasets! |
@glenn-jocher If I want to add another model e.g VGG16 to the backbone, what is the right way to do that? |
@xengst you could try to create backbone modifications in a yaml file, though be aware that the head and backbone are connected at many different places by shortcut connections and not just at the end of the backbone. |
@glenn-jocher Thank your for your reply. So I should define all VGG16 layer as class first in |
@xengst yes. Remember the head needs skip connections from P3, P4, P5 (layers 6, 4 and 10 here): Lines 27 to 48 in 5185981
|
@glenn-jocher So what i am trying to do it wouldn't work ? if I want to test different head and backbone is not possible? |
@xengst how would I know if your experiment will 'work' or not? |
@glenn-jocher Can I directly add a layer to |
@myasser63 yes Detect can accept inputs from any part of the model. If you update Detect inputs you probably also want to set |
Thanks @glenn-jocher four your explanation |
@glenn-jocher I want to understant the concept behind choosing
|
❔Question
In yolo5s.yaml, there is only three detection layer [P3/8, P4/16, P5/32], how to add another layer with scale 64 to detect really big objects?
Additional context
Could you please kindly give me some guide? Thanks. @glenn-jocher
The text was updated successfully, but these errors were encountered: