{"record":{"id":"6344e4a9406776d2","repo":"PaddlePaddle/PaddleOCR","slug":"out-size-must-be-an-integer-or-tuple-of-integers","errorCode":null,"errorMessage":"\"out_size\" must be an integer or tuple of integers","messagePattern":"\"out_size\" must be an integer or tuple of integers","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ppocr/ext_op/roi_align_rotated/roi_align_rotated.py","lineNumber":51,"sourceCode":"\nclass RoIAlignRotated(nn.Layer):\n    \"\"\"RoI align pooling layer for rotated proposals.\"\"\"\n\n    def __init__(\n        self, out_size, spatial_scale, sample_num=0, aligned=True, clockwise=False\n    ):\n        super(RoIAlignRotated, self).__init__()\n\n        if isinstance(out_size, int):\n            self.out_h = out_size\n            self.out_w = out_size\n        elif isinstance(out_size, tuple):\n            assert len(out_size) == 2\n            assert isinstance(out_size[0], int)\n            assert isinstance(out_size[1], int)\n            self.out_h, self.out_w = out_size\n        else:\n            raise TypeError('\"out_size\" must be an integer or tuple of integers')\n\n        self.spatial_scale = float(spatial_scale)\n        self.sample_num = int(sample_num)\n        self.aligned = aligned\n        self.clockwise = clockwise\n\n    def forward(self, feats, rois):\n        output = roi_align_rotated(\n            feats,\n            rois,\n            self.out_h,\n            self.out_w,\n            self.spatial_scale,\n            self.sample_num,\n            self.aligned,\n            self.clockwise,\n        )\n        return output","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/ppocr/ext_op/roi_align_rotated/roi_align_rotated.py#L33-L69","documentation":"RoIAlignRotated.__init__ validates its out_size argument: it accepts only a single int (used for both output height and width) or a tuple of exactly two ints. Any other type (float, list, string, 3-element tuple) raises TypeError at construction time. This guards downstream shape computation in the rotated RoI align CUDA/OP call which needs concrete integer out_h/out_w.","triggerScenarios":"Instantiating RoIAlignRotated(out_size=7.0), out_size=\"14\", out_size=[7, 7] (list, not tuple), or out_size=(7, 7, 7) (len != 2); also a tuple containing non-int entries like (7.0, 7.0).","commonSituations":"Copy-pasting a config value as a float (e.g. from YAML where 7 parses as float, or writing 7.0), passing a list because other PaddleOCR APIs accept lists, or programmatically building the tuple from float math (ceil/floor results).","solutions":["Pass a plain int: RoIAlignRotated(out_size=14)","Or pass a 2-tuple of ints: RoIAlignRotated(out_size=(7, 7))","If the value comes from computation or config, coerce first: out_size=(int(h), int(w))"],"exampleFix":"# before\nRoIAlignRotated(out_size=7.0)      # TypeError\nRoIAlignRotated(out_size=[7, 7])    # TypeError (list)\n\n# after\nRoIAlignRotated(out_size=7)\nRoIAlignRotated(out_size=(7, 7))","handlingStrategy":"type-guard","validationCode":"def valid_out_size(v):\n    return isinstance(v, int) or (\n        isinstance(v, tuple) and len(v) == 2 and all(isinstance(i, int) for i in v)\n    )\n\nassert valid_out_size(out_size), 'out_size must be int or 2-tuple of ints'","typeGuard":"def is_valid_out_size(v) -> bool:\n    if isinstance(v, bool):\n        return False\n    if isinstance(v, int):\n        return True\n    return isinstance(v, tuple) and len(v) == 2 and all(\n        isinstance(i, int) and not isinstance(i, bool) for i in v\n    )","tryCatchPattern":null,"preventionTips":["Normalize config values once at load: coerce to (int(h), int(w)) before constructing the op","When computing sizes from arithmetic (ceil, ratio math), wrap with int() explicitly","Add a unit test that constructs RoIAlignRotated with your config object to catch bad types at CI time"],"tags":["config","type-error","roi-align","constructor-validation"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}