{"record":{"id":"9a5f18b57865d418","repo":"open-mmlab/mmdetection","slug":"center-offset-should-be-in-range-0-1-center-o","errorCode":null,"errorMessage":"center_offset should be in range [0, 1], {center_offset} is given.","messagePattern":"center_offset should be in range \\[0, 1\\], (.+?) is given\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mmdet/models/task_modules/prior_generators/anchor_generator.py","lineNumber":85,"sourceCode":"    \"\"\"\n\n    def __init__(self,\n                 strides: Union[List[int], List[Tuple[int, int]]],\n                 ratios: List[float],\n                 scales: Optional[List[int]] = None,\n                 base_sizes: Optional[List[int]] = None,\n                 scale_major: bool = True,\n                 octave_base_scale: Optional[int] = None,\n                 scales_per_octave: Optional[int] = None,\n                 centers: Optional[List[Tuple[float, float]]] = None,\n                 center_offset: float = 0.,\n                 use_box_type: bool = False) -> None:\n        # check center and center_offset\n        if center_offset != 0:\n            assert centers is None, 'center cannot be set when center_offset' \\\n                                    f'!=0, {centers} is given.'\n        if not (0 <= center_offset <= 1):\n            raise ValueError('center_offset should be in range [0, 1], '\n                             f'{center_offset} is given.')\n        if centers is not None:\n            assert len(centers) == len(strides), \\\n                'The number of strides should be the same as centers, got ' \\\n                f'{strides} and {centers}'\n\n        # calculate base sizes of anchors\n        self.strides = [_pair(stride) for stride in strides]\n        self.base_sizes = [min(stride) for stride in self.strides\n                           ] 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' \\","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/models/task_modules/prior_generators/anchor_generator.py#L67-L103","documentation":"AnchorGenerator.__init__ requires center_offset to be within [0, 1] (0.5 is the standard 'center' anchor placement). Values outside that range raise ValueError because anchor centers would fall outside feature cells.","triggerScenarios":"anchor_generator=dict(type='AnchorGenerator', center_offset=1.5) or a negative value; also configs where center_offset is computed and overshoots the range.","commonSituations":"Tuning anchor centering for special heads (corner-aligned anchors), typos like center_offset=5 instead of 0.5.","solutions":["Use center_offset=0.5 (default, pixel centers) or 0 (corner-aligned)","If you also set `centers`, note center_offset must be 0 — remove one of them"],"exampleFix":"# before\nanchor_generator=dict(..., center_offset=0.55)\n# after\nanchor_generator=dict(..., center_offset=0.5)","handlingStrategy":"validation","validationCode":"co = cfg.get('center_offset', 0.5)\nassert isinstance(co, (int, float)) and 0 <= co <= 1","typeGuard":"def valid_center_offset(v) -> bool: return isinstance(v,(int,float)) and 0 <= v <= 1","tryCatchPattern":null,"preventionTips":["Leave center_offset at default 0.5","Do not combine nonzero center_offset with explicit `centers`"],"tags":["mmdetection","anchor-generator","config"],"backgroundTag":"invalid-config-value","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}