{"record":{"id":"d12950d93194552e","repo":"open-mmlab/mmdetection","slug":"invalid-scale-scale-must-be-positive","errorCode":null,"errorMessage":"Invalid scale {scale}, must be positive.","messagePattern":"Invalid scale (.+?), must be positive\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mmdet/datasets/transforms/transforms.py","lineNumber":82,"sourceCode":"                 return_scale: bool = False) -> tuple:\n    \"\"\"Calculate the new size to be rescaled to.\n\n    Args:\n        old_size (tuple[int]): The old size (w, h) of image.\n        scale (float | tuple[int]): The scaling factor or maximum size.\n            If it is a float number, then the image will be rescaled by this\n            factor, else if it is a tuple of 2 integers, then the image will\n            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","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/datasets/transforms/transforms.py#L64-L100","documentation":"rescale_size() (backing imrescale and the Resize transform) computes the scale factor for resizing. When `scale` is a number it must be strictly positive; a value of 0 or a negative number is meaningless as a multiplicative scale and raises ValueError.","triggerScenarios":"Calling imrescale(img, scale) or configuring dict(type='Resize', scale=0) / scale=-1 / any float <= 0, including scale computed dynamically (e.g. scale_factor * 0) or a typo like scale=0.5 written as 0.","commonSituations":"Dynamically computed scale factors that evaluate to 0 (empty tensor, division producing 0); typos in config scale values; scale sourced from a variable that defaults to 0 before assignment.","solutions":["Fix the scale value to a positive number (e.g. 1.0 to keep size, 0.5 to halve)","If scale is computed, guard it: max(scale, eps) or assert scale > 0 before calling Resize/imrescale","For absolute target sizes, pass a tuple like (1333, 800) instead of a numeric factor"],"exampleFix":"# before\ndict(type='Resize', scale=0, keep_ratio=True)\n# after\ndict(type='Resize', scale=1.0, keep_ratio=True)","handlingStrategy":"validation","validationCode":"assert isinstance(scale, (int, float)) and scale > 0, f'bad scale: {scale}'\n# or clamp: scale = max(scale, 1e-6)","typeGuard":"def is_valid_scale(scale) -> bool:\n    return isinstance(scale, (int, float)) and not isinstance(scale, bool) and scale > 0","tryCatchPattern":"try:\n    img2 = mmcv.imrescale(img, scale)\nexcept ValueError:\n    raise ValueError(f'rescale scale must be > 0, got {scale}') from None","preventionTips":["Validate dynamically computed scale factors before building the Resize transform","Prefer explicit tuples for target sizes in configs"],"tags":["mmdetection","resize","valueerror","config-validation","scale"],"backgroundTag":"invalid-argument-value","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}