huggingface/pytorch-image-models · warning

final_scale_range values should ideally be between 0.0 and 1

Error message

final_scale_range values should ideally be between 0.0 and 1.0.

What it means

After validating ordering, RandomResizedCropToSequence checks that final_scale_range lies within [0.0, 1.0]. A warning (no error) means values fall outside, e.g. (1.0, 1.5), which can produce upsampling or crops larger than the source image during final-scale randomization.

Source

Thrown at timm/data/naflex_transforms.py:584

        if isinstance(interpolation, str):
            if interpolation == 'random':
                self.interpolation = _RANDOM_INTERPOLATION
            else:
                self.interpolation = str_to_interp_mode(interpolation)
        else:
            self.interpolation = interpolation

        # Validate scale and ratio
        self.scale = _validate_range(self.scale, "scale")
        self.ratio = _validate_range(self.ratio, "ratio")

        # Validate final_scale_range if provided
        if self.final_scale_range is not None:
            self.final_scale_range = _validate_range(self.final_scale_range, "final_scale_range")

            # Additional validation for final_scale_range values
            if not (0.0 <= self.final_scale_range[0] <= self.final_scale_range[1] <= 1.0):
                warnings.warn("final_scale_range values should ideally be between 0.0 and 1.0.")

    @staticmethod
    def get_params(
            img: torch.Tensor,
            scale: Tuple[float, float],
            ratio: Tuple[float, float],
            crop_attempts: int = 10,
            patch_h: int = 16,
            patch_w: int = 16,
            max_seq_len: int = 1024,
            divisible_by_patch: bool = True,
            max_ratio: Optional[float] = None,
            final_scale_range: Optional[Tuple[float, float]] = None,
            interpolation: Union[List[InterpolationMode], InterpolationMode] = _RANDOM_INTERPOLATION,
    ) -> Tuple[Tuple[int, int, int, int], Tuple[int, int], InterpolationMode]:
        """ Get parameters for a random sized crop relative to image aspect ratio.
        """
        _, height, width = F.get_dimensions(img)

View on GitHub (pinned to 9a5261e31b)

Solutions

  1. Keep final_scale_range within (0, 1], e.g. (0.8, 1.0)
  2. If you truly need upsampling, verify output behavior and suppress the warning deliberately
  3. Re-read the transform docstring for the intended scale semantics

Example fix

# before
tfm = RandomResizedCropToSequence(..., final_scale_range=(1.0, 1.33))
# after
tfm = RandomResizedCropToSequence(..., final_scale_range=(0.75, 1.0))
Defensive patterns

Strategy: validation

Validate before calling

lo, hi = final_scale_range\nassert 0.0 <= lo <= hi <= 1.0, 'final_scale_range should be within [0, 1]'

Prevention

When it happens

Trigger: Passing final_scale_range=(1.0, 1.33) for a mild zoom-out augmentation; mixing up scale semantics from RandomResizedCrop's area-scale (which is also <=1 in timm's impl).

Common situations: Configs tuned for torchvision RandomResizedCrop where scale > 1 sometimes appears; intending 'zoom' ranges. Crops may still be clamped by downstream max_seq_len logic, but results can be unexpected.

Related errors


AI-assisted analysis of huggingface/pytorch-image-models@9a5261e31b (2026-08-27). Data as JSON: /api/errors/e1437d1fbdf3dba0. Report an issue: GitHub.