Skip to content

Commit b7d9033

Browse files
Ailing Zhangfacebook-github-bot
authored andcommitted
add notes about overshoot in bicubic mode (#23321)
Summary: fix #21044 Bicubic interpolation can cause overshoot. Opencv keeps results dtype aligned with input dtype: - If input is uint8, the result is clamped [0, 255] - If input is float, the result is unclamped. In Pytorch case, we only accept float input, so we'll keep the result unclamped, and add some notes so that users can explicitly call `torch.clamp()` when necessary. Pull Request resolved: #23321 Differential Revision: D16464796 Pulled By: ailzhang fbshipit-source-id: 177915e525d1f54c2209e277cf73e40699ed1acd
1 parent d522b3c commit b7d9033

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

torch/nn/functional.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2370,6 +2370,12 @@ def upsample(input, size=None, scale_factor=None, mode='nearest', align_corners=
23702370
``'bilinear'``, ``'bicubic'`` or ``'trilinear'``.
23712371
Default: ``False``
23722372
2373+
.. note::
2374+
With ``mode='bicubic'``, it's possible to cause overshoot, in other words it can produce
2375+
negative values or values greater than 255 for images.
2376+
Explicitly call ``result.clamp(min=0, max=255)`` if you want to reduce the overshoot
2377+
when displaying the image.
2378+
23732379
.. warning::
23742380
With ``align_corners = True``, the linearly interpolating modes
23752381
(`linear`, `bilinear`, and `trilinear`) don't proportionally align the
@@ -2417,6 +2423,12 @@ def interpolate(input, size=None, scale_factor=None, mode='nearest', align_corne
24172423
``'bilinear'``, ``'bicubic'``, or ``'trilinear'``.
24182424
Default: ``False``
24192425
2426+
.. note::
2427+
With ``mode='bicubic'``, it's possible to cause overshoot, in other words it can produce
2428+
negative values or values greater than 255 for images.
2429+
Explicitly call ``result.clamp(min=0, max=255)`` if you want to reduce the overshoot
2430+
when displaying the image.
2431+
24202432
.. warning::
24212433
With ``align_corners = True``, the linearly interpolating modes
24222434
(`linear`, `bilinear`, and `trilinear`) don't proportionally align the

0 commit comments

Comments
 (0)