Fix: use resample-aware bilinear+antialias interpolation for tensor/numpy resize in VaeImageProcessor#13500
Conversation
Code Review: Fix resample-aware interpolation in VaeImageProcessorSummaryThis fixes a legitimate quality bug: Issues
VerdictRequest changes — The core fix is correct, but needs tests, the lanczos mapping deserves discussion, and the import path should be consistent. |
|
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. |
yiyixuxu
left a comment
There was a problem hiding this comment.
thanks for the PR!
i left one comment
| "linear": ("bilinear", True), | ||
| "bilinear": ("bilinear", True), | ||
| "bicubic": ("bicubic", True), | ||
| "lanczos": ("bilinear", True), |
There was a problem hiding this comment.
ohh, so if this option is not supported in torch, let's not map it to anything
just send a warning that says this resample mode is not supported for tensor/ndarray so it will be ignored (the default nearest is used intead). this way we don't change the default behavior for resize
what do you think?
|
Thanks @yiyixuxu — updated! Revised approach:
|
…nsor/numpy resize branch
799e72c to
d3456ea
Compare
What does this PR do?
VaeImageProcessorexposes aresampleconfig parameter (defaulting to"lanczos")and correctly applies it when resizing PIL images via
PIL_INTERPOLATION. However,the two
torch.nn.functional.interpolatecalls handlingtorch.Tensorandnp.ndarrayinputs passed nomodeargument — causing PyTorch to silently defaultto
"nearest"neighbor interpolation, regardless of the configured resample filter.No
antialias=Truewas set either, causing aliasing artifacts on downsampling.This fix:
TORCH_INTERPOLATIONdict inpil_utils.pymapping the same resample-stringkeys as
PIL_INTERPOLATIONto theirtorch.nn.functional.interpolateequivalents(with
antialiaseligibility)."lanczos"maps tobilinear+antialias, the closesthigh-quality torch substitute.
VaeImageProcessor.resize()to use the mapped modeand antialias flag, making tensor/numpy resize quality consistent with the PIL path.
This silently affected every pipeline that passes
torch.Tensorinputs toVaeImageProcessor(ControlNet conditioning, IP-Adapter, img2img, etc.).Fixes # (issue)
Before submitting
that's the case).
(important for complex PRs)?
forum?
Please add a link to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
@yiyixuxu @sayakpaul @DN6