BasicSR icon indicating copy to clipboard operation
BasicSR copied to clipboard

Fix import error for rgb_to_grayscale

Open sipsmehta opened this issue 10 months ago • 1 comments

The import statement for rgb_to_grayscale was referencing the torchvision.transforms.functional_tensor module, which is not available in the current version of torchvision. Updated the import statement to use torchvision.transforms.functional instead, resolving the ModuleNotFoundError.

This commit fixes the issue where the script was failing to run due to the missing module. The change ensures compatibility with the installed version of torchvision and allows the script to execute successfully.

sipsmehta avatar May 01 '24 11:05 sipsmehta

This might break installations depending on older version of torchvision. Instead, let's make it more compatible.

try:
    from torchvision.transforms.functional import rgb_to_grayscale
except ImportError:
    try:
        from torchvision.transforms.functional_tensor import rgb_to_grayscale
    except ImportError:
        raise ImportError("Failed to import rgb_to_grayscale from torchvision. Ensure you have a compatible version of torchvision installed.")

Elawphant avatar May 12 '24 10:05 Elawphant