XPixelGroup / BasicSR

Open Source Image and Video Restoration Toolbox for Super-resolution, Denoise, Deblurring, etc. Currently, it includes EDSR, RCAN, SRResNet, SRGAN, ESRGAN, EDVR, BasicVSR, SwinIR, ECBSR, etc. Also support StyleGAN2, DFDNet.
https://basicsr.readthedocs.io/en/latest/
Apache License 2.0
6.44k stars 1.14k forks source link

Fix import error for rgb_to_grayscale #677

Open sipsmehta opened 2 months ago

sipsmehta commented 2 months ago

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.

Elawphant commented 1 month ago

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.")