{"record":{"id":"cbe1e9fba207e8d6","repo":"open-mmlab/mmdetection","slug":"either-scales-or-octave-base-scale-with-scales-per","errorCode":null,"errorMessage":"Either scales or octave_base_scale with scales_per_octave should be set","messagePattern":"Either scales or octave_base_scale with scales_per_octave should be set","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mmdet/models/task_modules/prior_generators/anchor_generator.py","lineNumber":113,"sourceCode":"                           ] if base_sizes is None else base_sizes\n        assert len(self.base_sizes) == len(self.strides), \\\n            'The number of strides should be the same as base sizes, got ' \\\n            f'{self.strides} and {self.base_sizes}'\n\n        # calculate scales of anchors\n        assert ((octave_base_scale is not None\n                 and scales_per_octave is not None) ^ (scales is not None)), \\\n            'scales and octave_base_scale with scales_per_octave cannot' \\\n            ' be set at the same time'\n        if scales is not None:\n            self.scales = torch.Tensor(scales)\n        elif octave_base_scale is not None and scales_per_octave is not None:\n            octave_scales = np.array(\n                [2**(i / scales_per_octave) for i in range(scales_per_octave)])\n            scales = octave_scales * octave_base_scale\n            self.scales = torch.Tensor(scales)\n        else:\n            raise ValueError('Either scales or octave_base_scale with '\n                             'scales_per_octave should be set')\n\n        self.octave_base_scale = octave_base_scale\n        self.scales_per_octave = scales_per_octave\n        self.ratios = torch.Tensor(ratios)\n        self.scale_major = scale_major\n        self.centers = centers\n        self.center_offset = center_offset\n        self.base_anchors = self.gen_base_anchors()\n        self.use_box_type = use_box_type\n\n    @property\n    def num_base_anchors(self) -> List[int]:\n        \"\"\"list[int]: total number of base anchors in a feature grid\"\"\"\n        return self.num_base_priors\n\n    @property\n    def num_base_priors(self) -> List[int]:","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/models/task_modules/prior_generators/anchor_generator.py#L95-L131","documentation":"AnchorGenerator needs anchor scales defined either explicitly via `scales` or implicitly via octave_base_scale together with scales_per_octave (RetinaNet-style octave scales). Providing neither raises ValueError in __init__.","triggerScenarios":"anchor_generator=dict(type='AnchorGenerator', ratios=[0.5,1.0,2.0]) with both scales and octave_base_scale omitted; or passing only scales_per_octave without octave_base_scale.","commonSituations":"Hand-writing anchor configs and forgetting the scale entry; partial deletion of a RetinaNet anchor generator config; passing octave_base_scale=None after tweaking.","solutions":["Add explicit scales, e.g. scales=[8, 16, 32, 64]","Or for FPN heads set octave_base_scale=4 and scales_per_octave=3 with strides [8,16,32,64,128] to derive scales","Copy the anchor_generator block from a known-good config of the same detector type"],"exampleFix":"# before\nanchor_generator=dict(type='AnchorGenerator', strides=[8,16,32], ratios=[0.5,1.0,2.0])\n# after\nanchor_generator=dict(type='AnchorGenerator', strides=[8,16,32], ratios=[0.5,1.0,2.0], scales=[8,16,32])","handlingStrategy":"validation","validationCode":"has_scales = 'scales' in cfg and cfg['scales'] is not None\nhas_octave = cfg.get('octave_base_scale') is not None and cfg.get('scales_per_octave') is not None\nassert has_scales or has_octave","typeGuard":"def anchor_scales_defined(c: dict) -> bool: return (c.get('scales') is not None) or (c.get('octave_base_scale') is not None and c.get('scales_per_octave') is not None)","tryCatchPattern":null,"preventionTips":["Always specify scales (or octave pair) in anchor_generator configs","Derive configs from shipped detector configs of the same family"],"tags":["mmdetection","anchor-generator","config"],"backgroundTag":"missing-required-config-field","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}