• DepthAI
  • Changing model size when training returns output layer width error

Hello medonni ,
I believe you need to copy anchors/masks from the generated json (or just use that json) when following the yolov5 training notebook. Have you taken that step?
Thanks, Erik

    erik Hey Erik!

    Which json are you exactly referring to?
    The only mentions of json in the notebook are save_json=False in the validation step, and in the on-device decoding where its explained that we should only just change num of classes and labels.

    What am i missing here?

    Thanks in advance!

    • erik replied to this.

      Hello medonni ,
      I have reread your initial post and I am not sure, have you changed the default resolution (416x416)? If you haven't, the JSON at the depthai-experiments should work as expected.
      Thanks, Erik

        erik Hey!

        Yea, i'm trying to change the model to a bigger size, currently trying a 640x640. The first model i trained was at 416x416 and it worked fine with the provided JSON.

        The issue is that from what i realized, the model size is directly tied to the size of preview window and it being at 416x416 is just a tad bit small, therefore i want to up the size a little bit.

        • NKG replied to this.

          Resolved thanks to Conor on discord.

          Issue was that anchor masks change based on the actual model size, so for 640x640 i needed 80/40/20 masks in the config. To calculate it we should do size/32, size/16, size/8, and use the obtained anchor masks.

            6 months later

            stephansturges

            Hey!

            sorry for the late reply.

            Here is the JSON as of today.

            {
            "nn_config": {
            "output_format": "detection",
            "NN_family": "YOLO",
            "input_size" : "416x416",
            "NN_specific_metadata": {
            "classes": 1,
            "coordinates": 4,
            "anchors": [
            10, 13, 16, 30, 33, 23, 30, 61, 62, 45, 59, 119, 116, 90, 156, 198, 373,
            326
            ],
            "anchor_masks" : {
            "side52": [0, 1, 2],
            "side26": [3, 4, 5],
            "side13": [6, 7, 8]
            },
            "iou_threshold": 0.5,
            "confidence_threshold": 0.65
            }
            },
            "mappings": {
            "labels": ["plate"]
            }
            }

            Hope this helps!

              2 months later

              Hello medonni stephansturges
              I have tried suggested solution it's not working for me.
              Can you send me working JSON file for custom yolov5 model ...
              ERROR - [DetectionNetwork(1)] [error] Mask is not defined for output layer with width '6'. Define at pipeline build time using: 'setAnchorMasks' for 'side6'

                StavanRupareliya Unfortunately not, as i do not have the access to it anymore.

                What is the model size you are trying to do?

                medonni
                Hey I'm using a pretrained model model_name = "yolov5n_coco_416x416", zoo_type = "depthai" and I continuosly get this error [SpatialDetectionNetwork(1)] [error] Mask is not defined for output layer with width '52'. Define at pipeline build time using: 'setAnchorMasks' for 'side52'.
                The pretrained network works fine for my use case so I was not training it and I'm not sure how to resolve the above error?

                4 months later

                Hey
                i used a custom gesture detection from https://pyimagesearch.com/2023/05/01/training-the-yolov8-object-detector-for-oak-d/
                after converting the pt to blob using the tool
                {

                    "model": {

                        "xml": "yolov8ntrained.xml",

                        "bin": "yolov8ntrained.bin"

                    },

                    "nn_config": {

                        "output_format": "detection",

                        "NN_family": "YOLO",

                        "input_size": "416x416",

                        "NN_specific_metadata": {

                            "classes": 5,

                            "coordinates": 4,

                            "anchors": [],

                            "anchor_masks": {},

                            "iou_threshold": 0.5,

                            "confidence_threshold": 0.5

                        }

                    },

                    "mappings": {

                        "labels": [

                            "Class_0",

                            "Class_1",

                            "Class_2",

                            "Class_3",

                            "Class_4"

                        ]

                    },

                    "version": 1

                }
                [DetectionNetwork(1)] [error] Mask is not defined for output layer with width '52'. Define at pipeline build time using: 'setAnchorMasks' for 'side52'.
                this is the error i get
                is this a issue i changed the default input size to 416x416 instead of 640x640

                There is no anchormasks for the json file i provided
                can u tell me what i did wrong?

                • erik replied to this.

                  krishnashravan you need to define masks/anchors, you currently have this empty:

                  "anchors": [],
                  "anchor_masks": {},

                  If you have .pt model, you can use tools.luxonis.com, which will return the json together with the anchors/masks.

                  I used the tools to get the blob file along with the json file thats the json file from the luxonis tool

                  • erik replied to this.

                    the pt files
                    the hand gesture that is nano and small model trained with 416 input size (handntrained and handstrained)
                    the person detection that is nano trained with 640 input size (personntrained)

                    • erik replied to this.

                      erik

                      No not yet

                      Just now i tried with the yolov8 training colab file from the repo i'm getting the same empty anchor values