{"record":{"id":"d1a31acdd3a48e2d","repo":"open-mmlab/mmdetection","slug":"scale-must-be-a-number-or-tuple-of-int-but-got-t","errorCode":null,"errorMessage":"Scale must be a number or tuple of int, but got {type(scale)}","messagePattern":"Scale must be a number or tuple of int, but got (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"mmdet/datasets/transforms/transforms.py","lineNumber":90,"sourceCode":"            be rescaled as large as possible within the scale.\n        return_scale (bool): Whether to return the scaling factor besides the\n            rescaled image size.\n\n    Returns:\n        tuple[int]: The new rescaled image size.\n    \"\"\"\n    w, h = old_size\n    if isinstance(scale, (float, int)):\n        if scale <= 0:\n            raise ValueError(f'Invalid scale {scale}, must be positive.')\n        scale_factor = scale\n    elif isinstance(scale, tuple):\n        max_long_edge = max(scale)\n        max_short_edge = min(scale)\n        scale_factor = min(max_long_edge / max(h, w),\n                           max_short_edge / min(h, w))\n    else:\n        raise TypeError(\n            f'Scale must be a number or tuple of int, but got {type(scale)}')\n    # only change this\n    new_size = _fixed_scale_size((w, h), scale_factor)\n\n    if return_scale:\n        return new_size, scale_factor\n    else:\n        return new_size\n\n\ndef imrescale(\n    img: np.ndarray,\n    scale: Union[float, Tuple[int, int]],\n    return_scale: bool = False,\n    interpolation: str = 'bilinear',\n    backend: Optional[str] = None\n) -> Union[np.ndarray, Tuple[np.ndarray, float]]:\n    \"\"\"Resize image while keeping the aspect ratio.","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/datasets/transforms/transforms.py#L72-L108","documentation":"rescale_size() only accepts a numeric scale factor or a tuple of numbers (interpreted as (max_long_edge, max_short_edge)). Any other type — a list [1333, 800], a string, None, or a numpy array — raises TypeError listing the offending type.","triggerScenarios":"Calling Resize/imrescale with scale as a Python list (a very common config slip, since configs freely use lists elsewhere), scale=None, or scale=np.array([800, 1333]).","commonSituations":"Writing dict(type='Resize', scale=[1333, 800]) instead of (1333, 800) in a config; passing scale=None when the intent was keep_ratio with a factor; numpy arrays produced by programmatic pipeline builders.","solutions":["Use a tuple for size pairs: scale=(1333, 800), not a list","For a pure factor use a float: scale=0.5","In programmatic pipelines, coerce: scale=tuple(scale) if isinstance(scale, list) else scale"],"exampleFix":"# before\ndict(type='Resize', scale=[1333, 800], keep_ratio=True)\n# after\ndict(type='Resize', scale=(1333, 800), keep_ratio=True)","handlingStrategy":"validation","validationCode":"assert isinstance(scale, (int, float, tuple)), f'scale must be number or tuple, got {type(scale)}'\nif isinstance(scale, list): scale = tuple(scale)","typeGuard":"def is_valid_scale_arg(scale) -> bool:\n    return isinstance(scale, (int, float)) or (isinstance(scale, tuple) and len(scale) == 2)","tryCatchPattern":"try:\n    new_size = mmcv.imrescale(img, scale)\nexcept TypeError:\n    raise TypeError(f'Resize scale must be number or 2-tuple, got {type(scale).__name__}') from None","preventionTips":["Always write size pairs as tuples, never lists, in mmdet configs","Run a one-sample pipeline smoke test to catch config type errors early"],"tags":["mmdetection","resize","typeerror","config-validation","type-mismatch"],"backgroundTag":"invalid-argument-type","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}