tensorflow/models · error · ValueError
image_size must be a positive multiple of {patch_size}, got
Error message
image_size must be a positive multiple of {patch_size}, got {image_size}. What it means
Error "image_size must be a positive multiple of {patch_size}, got {image_size}." thrown in tensorflow/models.
Source
Thrown at official/projects/waste_identification_ml/fine_tuning/Dinov3_image_classifier/models.py:66
DEFAULT_NUMBER_OF_CLASSES = 2
# DINOv3 ViT backbones use 16x16 patches. Input image sizes must be a
# multiple of this value so the patch embedding tiles cleanly.
DINOV3_PATCH_SIZE = 16
def validate_image_size(image_size: int, patch_size: int) -> None:
"""Verifies that the chosen image size is a multiple of the patch size.
Args:
image_size: Side length in pixels of the square input image.
patch_size: Side length in pixels of the backbone's patch embedding.
Raises:
ValueError: If `image_size` is not a positive multiple of `patch_size`.
"""
if image_size <= 0 or image_size % patch_size != 0:
raise ValueError(
f"image_size must be a positive multiple of {patch_size}, "
f"got {image_size}."
)
def load_model(
model_name: str,
repo_dir: pathlib.Path,
weights: pathlib.Path | None = None,
) -> nn.Module:
"""Loads a DINOv3 backbone via torch.hub from a local repository.
Args:
model_name: Name of the DINOv3 model variant (e.g., 'dinov3_vits16').
repo_dir: Path to the cloned Facebook DINOv3 repository.
weights: Optional path to a pretrained weights file. If None, the model is
loaded with random weights.
View on GitHub (pinned to e006f5f0d5)
When it happens
Trigger: Thrown at official/projects/waste_identification_ml/fine_tuning/Dinov3_image_classifier/models.py:66 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of tensorflow/models@e006f5f0d5 (2026-08-24).
Data as JSON: /api/errors/6a0dca7e7665c954.
Report an issue: GitHub.