{"record":{"id":"a5eef3da0376d900","repo":"huggingface/pytorch-image-models","slug":"input-image-must-have-positive-dimensions-got-h","errorCode":null,"errorMessage":"Input image must have positive dimensions, got H={height}, W={width}","messagePattern":"Input image must have positive dimensions, got H=(.+?), W=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"timm/data/naflex_transforms.py","lineNumber":604,"sourceCode":"    @staticmethod\n    def get_params(\n            img: torch.Tensor,\n            scale: Tuple[float, float],\n            ratio: Tuple[float, float],\n            crop_attempts: int = 10,\n            patch_h: int = 16,\n            patch_w: int = 16,\n            max_seq_len: int = 1024,\n            divisible_by_patch: bool = True,\n            max_ratio: Optional[float] = None,\n            final_scale_range: Optional[Tuple[float, float]] = None,\n            interpolation: Union[List[InterpolationMode], InterpolationMode] = _RANDOM_INTERPOLATION,\n    ) -> Tuple[Tuple[int, int, int, int], Tuple[int, int], InterpolationMode]:\n        \"\"\" Get parameters for a random sized crop relative to image aspect ratio.\n        \"\"\"\n        _, height, width = F.get_dimensions(img)\n        if height <= 0 or width <= 0:\n             raise ValueError(f\"Input image must have positive dimensions, got H={height}, W={width}\")\n\n        area = height * width\n        orig_aspect = width / height\n        log_ratio = (math.log(ratio[0]), math.log(ratio[1]))\n\n        for _ in range(crop_attempts):\n            target_area = area * random.uniform(scale[0], scale[1])\n            aspect_ratio_factor = math.exp(random.uniform(log_ratio[0], log_ratio[1]))\n            aspect_ratio = orig_aspect * aspect_ratio_factor\n\n            # Calculate target dimensions for the crop\n            # target_area = crop_w * crop_h, aspect_ratio = crop_w / crop_h\n            # => crop_h = sqrt(target_area / aspect_ratio)\n            # => crop_w = sqrt(target_area * aspect_ratio)\n            crop_h = int(round(math.sqrt(target_area / aspect_ratio)))\n            crop_w = int(round(math.sqrt(target_area * aspect_ratio)))\n\n            if 0 < crop_w <= width and 0 < crop_h <= height:","sourceCodeStart":586,"sourceCodeEnd":622,"githubUrl":"https://github.com/huggingface/pytorch-image-models/blob/9a5261e31b3b5128526eb2658333b4c0a54464ae/timm/data/naflex_transforms.py#L586-L622","documentation":"Thrown by RandomAspectRatioCrop.get_params when the input tensor/PIL image reports height or width <= 0. The crop parameter solver (which iterates over crop_attempts using log-ratio math) cannot operate on a degenerate image, so the transform validates dimensions up front.","triggerScenarios":"Passing a zero-sized tensor (e.g. shape (3,0,0) or (3,H,0)), a PIL image created with 0 width/height, or an image produced upstream by a broken decode/crop step into RandomAspectRatioCrop.forward.","commonSituations":"Corrupt or truncated image files that decode to empty arrays; unit tests using dummy zero-size tensors; a preceding transform (Resize with size 0, or a pad/crop with inverted coords) silently producing an empty image.","solutions":["Inspect/fix the upstream source of the image — print F.get_dimensions(img) before the transform to find where the size became 0.","If images come from a dataset, remove or repair corrupt files producing empty decodes.","Check any Resize/crop parameters in your pipeline for a 0 or negative size value.","Add a pre-transform guard that skips or replaces images with non-positive dimensions."],"exampleFix":"// before\nimg = Image.open(path).convert('RGB')\nout = RandomAspectRatioCrop()(img)\n\n// after\nimg = Image.open(path).convert('RGB')\n_, h, w = F.get_dimensions(img)\nif h <= 0 or w <= 0:\n    raise IOError(f'decoded empty image from {path}')\nout = RandomAspectRatioCrop()(img)","handlingStrategy":"validation","validationCode":"from timm.data import transforms_factory  # or torchvision.transforms.functional as F\nh, w = img.height, img.width  # PIL\nif h <= 0 or w <= 0:\n    raise IOError('empty image')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate decoded image dimensions before the transform pipeline.","Filter corrupt files at dataset build time.","In tests, use torch.randint(0, 256, (3, 224, 224)) tensors, never zero-size ones."],"tags":["timm","transforms","image-size","validation"],"backgroundTag":"invalid-image-dimensions","analyzedSha":"9a5261e31b3b5128526eb2658333b4c0a54464ae","analyzedAt":"2026-08-27T02:34:25.417Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}