{"record":{"id":"6a0dca7e7665c954","repo":"tensorflow/models","slug":"image-size-must-be-a-positive-multiple-of-patch-s","errorCode":null,"errorMessage":"image_size must be a positive multiple of {patch_size}, got {image_size}.","messagePattern":"image_size must be a positive multiple of (.+?), got (.+?)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/projects/waste_identification_ml/fine_tuning/Dinov3_image_classifier/models.py","lineNumber":66,"sourceCode":"DEFAULT_NUMBER_OF_CLASSES = 2\n\n# DINOv3 ViT backbones use 16x16 patches. Input image sizes must be a\n# multiple of this value so the patch embedding tiles cleanly.\nDINOV3_PATCH_SIZE = 16\n\n\ndef validate_image_size(image_size: int, patch_size: int) -> None:\n  \"\"\"Verifies that the chosen image size is a multiple of the patch size.\n\n  Args:\n    image_size: Side length in pixels of the square input image.\n    patch_size: Side length in pixels of the backbone's patch embedding.\n\n  Raises:\n    ValueError: If `image_size` is not a positive multiple of `patch_size`.\n  \"\"\"\n  if image_size <= 0 or image_size % patch_size != 0:\n    raise ValueError(\n        f\"image_size must be a positive multiple of {patch_size}, \"\n        f\"got {image_size}.\"\n    )\n\n\ndef load_model(\n    model_name: str,\n    repo_dir: pathlib.Path,\n    weights: pathlib.Path | None = None,\n) -> nn.Module:\n  \"\"\"Loads a DINOv3 backbone via torch.hub from a local repository.\n\n  Args:\n    model_name: Name of the DINOv3 model variant (e.g., 'dinov3_vits16').\n    repo_dir: Path to the cloned Facebook DINOv3 repository.\n    weights: Optional path to a pretrained weights file. If None, the model is\n      loaded with random weights.\n","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/projects/waste_identification_ml/fine_tuning/Dinov3_image_classifier/models.py#L48-L84","documentation":"Error \"image_size must be a positive multiple of {patch_size}, got {image_size}.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/projects/waste_identification_ml/fine_tuning/Dinov3_image_classifier/models.py:66 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e006f5f0d534913e49c1f1dae87364039fa607e2","analyzedAt":"2026-08-24T14:09:15.576Z","schemaVersion":2},"datasetVersion":"2026-08-24T17:17:21.512Z"}