huggingface/pytorch-image-models · warning
range should be of kind (min, max)
Error message
range should be of kind (min, max)
What it means
timm's RandomResizedCrop (and INTERCEPT mode variants) warn when scale=(min,max) or ratio=(min,max) is passed with min > max. Unlike naflex's _validate_range, here the values are NOT swapped — the range is used as-is, so sampling can behave unexpectedly.
Source
Thrown at timm/data/transforms.py:193
size: expected output size of each edge
scale: range of size of the origin size cropped
ratio: range of aspect ratio of the origin aspect ratio cropped
interpolation: Default: PIL.Image.BILINEAR
"""
def __init__(
self,
size,
scale=(0.08, 1.0),
ratio=(3. / 4., 4. / 3.),
interpolation='bilinear',
):
if isinstance(size, (list, tuple)):
self.size = tuple(size)
else:
self.size = (size, size)
if (scale[0] > scale[1]) or (ratio[0] > ratio[1]):
warnings.warn("range should be of kind (min, max)")
if interpolation == 'random':
self.interpolation = _RANDOM_INTERPOLATION
else:
self.interpolation = str_to_interp_mode(interpolation)
self.scale = scale
self.ratio = ratio
@staticmethod
def get_params(img, scale, ratio):
"""Get parameters for ``crop`` for a random sized crop.
Args:
img (PIL Image): Image to be cropped.
scale (tuple): range of size of the origin size cropped
ratio (tuple): range of aspect ratio of the origin aspect ratio cropped
Returns:View on GitHub (pinned to 9a5261e31b)
Solutions
- Rewrite ranges as (min, max)
- Audit any augmentation config where ranges were authored as (max, min)
Example fix
# before tfm = RandomResizedCrop(224, scale=(1.0, 0.08), ratio=(4./3., 3./4.)) # after tfm = RandomResizedCrop(224, scale=(0.08, 1.0), ratio=(3./4., 4./3.))
Defensive patterns
Strategy: validation
Validate before calling
assert scale[0] <= scale[1] and ratio[0] <= ratio[1], 'ranges must be (min, max)'
Prevention
- Note: unlike naflex, this class does NOT auto-swap; reversed ranges break sampling
- Standardize configs to (min, max) ordering
When it happens
Trigger: Creating RandomResizedCrop(224, scale=(0.9, 0.5)) or ratio=(4/3, 3/4); porting configs written as (max, min).
Common situations: Copy-pasted torchvision examples with reversed ratio; hand-tuned augmentation configs. Because no swap happens, downstream torch.empty(...).uniform_(lo, hi) with lo>hi raises or yields empty samples — fix the order.
Related errors
- {name.capitalize()} range reversed. Swapping.
- Input image must have positive dimensions, got H={height}, W
- Transform returned None for index {idx}. Skipping sample.
- final_scale_range values should ideally be between 0.0 and 1
- Final scale randomization ({scale_factor:.2f}) resulted in s
AI-assisted analysis of huggingface/pytorch-image-models@9a5261e31b (2026-08-27).
Data as JSON: /api/errors/c01da15412dc3906.
Report an issue: GitHub.