You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix CLI limitation for setting custom image size via model.image_size (#3460)
Fixes issue #3460 by enabling CLI-based configuration of input image size across all models without requiring manual pre-processor reconstruction.
After the pre-processor refactor, the CLI does not provide a simple way to modify image size. Users are forced to either:
1. Recreate the entire preprocessing pipeline via CLI arguments, or
2. Define a full YAML configuration just to change resize dimensions
This significantly reduces usability for a common operation.
This PR introduces `image_size` as a first-class parameter in `AnomalibModule` and propagates it through all model constructors.
The resizing is applied by patching the auto-created pre-processing pipeline using `_apply_image_size`, which:
- Updates the first `Resize` transform if present
- Inserts a `Resize` transform if missing
- Preserves existing transform attributes (e.g., interpolation, antialias)
- Updates `export_transform` for compatibility
Users can now directly set image size via CLI:
anomalib train --model Padim --model.image_size 512 --data MVTecAD --fast_dev_run True
anomalib train --model Padim --model.image_size "[512, 512]" --data MVTecAD --data.category transistor
anomalib train --model Stfpm --model.image_size 384 --data MVTecAD --data.category bottle --fast_dev_run True
jsonargparse exposes CLI arguments based on subclass `__init__` signatures. Therefore, `image_size` is added to each model constructor and forwarded to `AnomalibModule`, following the existing design pattern used for:
- pre_processor
- post_processor
- evaluator
- visualizer
This ensures:
- No CLI-level argument injection
- Consistent API across all models
- Full compatibility with config/CLI system
- Added `image_size` parameter to `AnomalibModule`
- Implemented `_apply_image_size` and `_rebuild_resize`
- Updated all model constructors to accept and forward `image_size`
- Removed the need for CLI or YAML preprocessing overrides
- Supports both int (square) and tuple (H, W)
- Applied only when `pre_processor=True` (default behavior)
- Does not override custom `PreProcessor` instances
- Fully backward compatible (default = None)
- Simplifies CLI usage for a common configuration task
- Eliminates need for verbose preprocessing definitions
- Aligns CLI behavior with Python API capabilities
Signed-off-by: Abhay Kumar Das <dasabhay.jsr@gmail.com>
0 commit comments