Skip to content

Conversation

@BreCaspian
Copy link

@BreCaspian BreCaspian commented Nov 11, 2025

Summary

Fix import error when using torchvision >= 0.15 where rgb_to_grayscale moved from
torchvision.transforms.functional_tensor to torchvision.transforms.functional.

Changes

Added backward-compatible import with fallback:

try:
    from torchvision.transforms.functional import rgb_to_grayscale  # torchvision >= 0.15
except Exception:
    from torchvision.transforms.functional_tensor import rgb_to_grayscale  # torchvision <= 0.14

Motivation

In torchvision >= 0.15, the module functional_tensor was removed.

This caused: ModuleNotFoundError: No module named 'torchvision.transforms.functional_tensor' when importing basicsr.data.degradations.

The patch keeps compatibility for both older and new versions of torchvision.

Tested Environment

Windows 11

Python: 3.9.20

Torch: 2.5.1+cu118

Torchvision: 0.20.1+cu118

Verified that import basicsr.data.degradations works on both old and new torchvision.

Validation

Ran pip install -e . and confirmed successful import of basicsr.data.degradations.

Backward compatible with torchvision <= 0.14.


屏幕截图 2025-11-11 222248 屏幕截图 2025-11-11 222316
屏幕截图 2025-11-11 222435 屏幕截图 2025-11-11 222449

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.

1 participant