Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resize relies on interpolate's native uint8 handling #7262

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .github/workflows/test-m1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,13 @@ jobs:
run: |
. ~/miniconda3/etc/profile.d/conda.sh
set -ex
conda run -p ${ENV_NAME} --no-capture-output python3 -u -mpytest -v --tb=long --durations 20

# Run resize benchmark
echo "--- Run resize benchmark ---"
# wget https://gist.githubusercontent.com/vfdev-5/a2e30ed50b5996807c9b09d5d33d8bc2/raw/8d4731c785140356a89c0afe4b012b304c4f1787/check_resize_uint8.py
curl https://gist.githubusercontent.com/vfdev-5/a2e30ed50b5996807c9b09d5d33d8bc2/raw/8d4731c785140356a89c0afe4b012b304c4f1787/check_resize_uint8.py -o /tmp/check_resize_uint8.py
conda run -p ${ENV_NAME} python3 -u /tmp/check_resize_uint8.py
echo "--- END Run resize benchmark ---"

# conda run -p ${ENV_NAME} --no-capture-output python3 -u -mpytest -v --tb=long --durations 20
conda env remove -p ${ENV_NAME}
5 changes: 4 additions & 1 deletion torchvision/transforms/v2/functional/_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,10 @@ def resize_image_tensor(
image = image.reshape(-1, num_channels, old_height, old_width)

dtype = image.dtype
need_cast = dtype not in (torch.float32, torch.float64)
acceptable_dtypes = [torch.float32, torch.float64]
if interpolation.value in ["nearest", "bilinear"]:
acceptable_dtypes.append(torch.uint8)
need_cast = dtype not in acceptable_dtypes
if need_cast:
image = image.to(dtype=torch.float32)

Expand Down