PaddlePaddle/PaddleOCR · error · TypeError

"out_size" must be an integer or tuple of integers

Error message

"out_size" must be an integer or tuple of integers

What it means

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.

Source

Thrown at ppocr/ext_op/roi_align_rotated/roi_align_rotated.py:51

class RoIAlignRotated(nn.Layer):
    """RoI align pooling layer for rotated proposals."""

    def __init__(
        self, out_size, spatial_scale, sample_num=0, aligned=True, clockwise=False
    ):
        super(RoIAlignRotated, self).__init__()

        if isinstance(out_size, int):
            self.out_h = out_size
            self.out_w = out_size
        elif isinstance(out_size, tuple):
            assert len(out_size) == 2
            assert isinstance(out_size[0], int)
            assert isinstance(out_size[1], int)
            self.out_h, self.out_w = out_size
        else:
            raise TypeError('"out_size" must be an integer or tuple of integers')

        self.spatial_scale = float(spatial_scale)
        self.sample_num = int(sample_num)
        self.aligned = aligned
        self.clockwise = clockwise

    def forward(self, feats, rois):
        output = roi_align_rotated(
            feats,
            rois,
            self.out_h,
            self.out_w,
            self.spatial_scale,
            self.sample_num,
            self.aligned,
            self.clockwise,
        )
        return output

View on GitHub (pinned to 2661c7c0ef)

Solutions

  1. Pass a plain int: RoIAlignRotated(out_size=14)
  2. Or pass a 2-tuple of ints: RoIAlignRotated(out_size=(7, 7))
  3. If the value comes from computation or config, coerce first: out_size=(int(h), int(w))

Example fix

# before
RoIAlignRotated(out_size=7.0)      # TypeError
RoIAlignRotated(out_size=[7, 7])    # TypeError (list)

# after
RoIAlignRotated(out_size=7)
RoIAlignRotated(out_size=(7, 7))
Defensive patterns

Strategy: type-guard

Validate before calling

def valid_out_size(v):
    return isinstance(v, int) or (
        isinstance(v, tuple) and len(v) == 2 and all(isinstance(i, int) for i in v)
    )

assert valid_out_size(out_size), 'out_size must be int or 2-tuple of ints'

Type guard

def is_valid_out_size(v) -> bool:
    if isinstance(v, bool):
        return False
    if isinstance(v, int):
        return True
    return isinstance(v, tuple) and len(v) == 2 and all(
        isinstance(i, int) and not isinstance(i, bool) for i in v
    )

Prevention

When it happens

Trigger: 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).

Common situations: 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).

Related errors


AI-assisted analysis of PaddlePaddle/PaddleOCR@2661c7c0ef (2026-08-14). Data as JSON: /api/errors/6344e4a9406776d2. Report an issue: GitHub.