Skip to content

Add image processors refactor to v5 migration guide#45556

Open
yonigozlan wants to merge 1 commit intohuggingface:mainfrom
yonigozlan:add-im-proc-refactor-mig-guide
Open

Add image processors refactor to v5 migration guide#45556
yonigozlan wants to merge 1 commit intohuggingface:mainfrom
yonigozlan:add-im-proc-refactor-mig-guide

Conversation

@yonigozlan
Copy link
Copy Markdown
Member

What does this PR do?

As discussed internally @vasqu
Cc @stevhliu

@HuggingFaceDocBuilderDev
Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Copy Markdown
Member

@stevhliu stevhliu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for adding!

Comment thread MIGRATION_GUIDE_V5.md

### Image Processors

The old slow/fast dual-file design — a PIL-based `image_processing_<model>.py` paired with a torchvision-based `image_processing_<model>_fast.py` — has been replaced with a named-backend architecture:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The old slow/fast dual-file design — a PIL-based `image_processing_<model>.py` paired with a torchvision-based `image_processing_<model>_fast.py` — has been replaced with a named-backend architecture:
The old slow/fast dual-file design has been replaced with a named-backend architecture. Each model previously had a PIL-based `image_processing_<model>.py` and a torchvision-based `image_processing_<model>_fast.py`. The new layout is:

Comment thread MIGRATION_GUIDE_V5.md
- `image_processing_<model>.py` → **torchvision** backend (default; was previously `FooImageProcessorFast`)
- `image_processing_pil_<model>.py` → **PIL** backend (was previously `FooImageProcessor`)

Processor classes now inherit from `TorchvisionBackend` or `PilBackend` (defined in `image_processing_backends.py`), which provide ready-made implementations of all standard operations (`resize`, `rescale`, `normalize`, `center_crop`, `pad`) and a default `_preprocess` pipeline. `BaseImageProcessor` (in `image_processing_utils`) handles the shared preprocessing boilerplate — kwargs validation, default-filling from class attributes, and input preparation — so model-specific processors contain only what is genuinely unique to the model. Most processors now simply inherit from a backend and declare class-attribute defaults; only processors with custom logic (e.g. patch tiling) need to override `_preprocess`.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Processor classes now inherit from `TorchvisionBackend` or `PilBackend` (defined in `image_processing_backends.py`), which provide ready-made implementations of all standard operations (`resize`, `rescale`, `normalize`, `center_crop`, `pad`) and a default `_preprocess` pipeline. `BaseImageProcessor` (in `image_processing_utils`) handles the shared preprocessing boilerplatekwargs validation, default-filling from class attributes, and input preparation — so model-specific processors contain only what is genuinely unique to the model. Most processors now simply inherit from a backend and declare class-attribute defaults; only processors with custom logic (e.g. patch tiling) need to override `_preprocess`.
Processor classes now inherit from `TorchvisionBackend` or `PilBackend` (defined in `image_processing_backends.py`), which provide ready-made implementations of all standard operations (`resize`, `rescale`, `normalize`, `center_crop`, `pad`) and a default `_preprocess` pipeline. `BaseImageProcessor` (in `image_processing_utils`) handles shared preprocessing boilerplate: kwargs validation, default-filling from class attributes, and input preparation. Model-specific processors contain only what is unique to the model. Most processors inherit from a backend and declare class-attribute defaults. Only those with custom logic (e.g. patch tiling) need to override `_preprocess`.

Comment thread MIGRATION_GUIDE_V5.md
- Minor change: `XXXFastImageProcessorKwargs` is removed in favor of `XXXImageProcessorKwargs` which will be shared between fast and slow processors (https://github.com/huggingface/transformers/pull/40931)


### Image Processors
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### Image Processors
### Image processors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants