Skip to content

fix(references/depth): resize() takes interpolation=, not mode= - #9644

Open
Anai-Guo wants to merge 1 commit into
pytorch:mainfrom
Anai-Guo:fix-stereo-eval-resize-interpolation
Open

fix(references/depth): resize() takes interpolation=, not mode=#9644
Anai-Guo wants to merge 1 commit into
pytorch:mainfrom
Anai-Guo:fix-stereo-eval-resize-interpolation

Conversation

@Anai-Guo

@Anai-Guo Anai-Guo commented Sep 3, 2026

Copy link
Copy Markdown

Problem

references/depth/stereo/train.py builds an eval preprocessing closure when --weights is passed, and that closure calls torchvision.transforms.functional.resize with a mode= keyword:

https://github.com/pytorch/vision/blob/main/references/depth/stereo/train.py#L225-L229

if disp is not None and not isinstance(disp, torch.Tensor):
    disp = torch.from_numpy(disp)
    if W_t != W_o:
        disp = resize(disp, (H_t, W_t), mode=InterpolationMode.BILINEAR) * scale_factor
if valid_disp_mask is not None and not isinstance(valid_disp_mask, torch.Tensor):
    valid_disp_mask = torch.from_numpy(valid_disp_mask)
    if W_t != W_o:
        valid_disp_mask = resize(valid_disp_mask, (H_t, W_t), mode=InterpolationMode.NEAREST)

resize has no mode parameter — the interpolation argument has always been called interpolation:

def resize(
    img: Tensor,
    size: list[int],
    interpolation: InterpolationMode = InterpolationMode.BILINEAR,
    max_size: Optional[int] = None,
    antialias: Optional[bool] = True,
) -> Tensor:

So both calls raise TypeError rather than resizing. The branch is guarded by W_t != W_o and by the disparity/mask still being numpy, which is why it has stayed unnoticed: it only fires when the loaded weights' transform actually rescales the width.

Reproduction

import numpy as np, torch
from torchvision.transforms.functional import InterpolationMode, resize

disp = torch.from_numpy(np.zeros((1, 10, 10), dtype="float32"))
resize(disp, (5, 5), mode=InterpolationMode.BILINEAR)
TypeError: resize() got an unexpected keyword argument 'mode'

Fix

Rename the keyword to interpolation at both call sites. Nothing else changes — the intended interpolation modes (BILINEAR for the disparity, NEAREST for the validity mask) are preserved.

Same snippet after the change:

disp = resize(disp, (5, 5), interpolation=InterpolationMode.BILINEAR)          # -> torch.Size([1, 5, 5])
resize(mask, (5, 5), interpolation=InterpolationMode.NEAREST)                  # -> torch.Size([1, 5, 5])

Both verified against an installed torchvision build, before and after.

🤖 Generated with Claude Code

`make_eval_loader` builds a `--weights` preprocessing closure that calls
`torchvision.transforms.functional.resize` with `mode=`:

    disp = resize(disp, (H_t, W_t), mode=InterpolationMode.BILINEAR) * scale_factor
    valid_disp_mask = resize(valid_disp_mask, (H_t, W_t), mode=InterpolationMode.NEAREST)

`resize` has no `mode` parameter -- its signature is
`resize(img, size, interpolation=..., max_size=None, antialias=True)` -- so
both calls raise `TypeError: resize() got an unexpected keyword argument
'mode'`. The branch is only reached when the loaded weights' transform
rescales the width (`W_t != W_o`) and the dataset yields numpy disparities,
which is why it has gone unnoticed.

Signed-off-by: Anai-Guo <antai12232931@outlook.com>
@pytorch-bot

pytorch-bot Bot commented Sep 3, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/vision/9644

Note: Links to docs will display an error until the docs builds have been completed.

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the cla signed label Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant