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

Fix bug with limit version of torchvision because of basicsr and gfpgan.archs #859

Open
wladradchenko opened this issue Oct 27, 2024 · 0 comments

Comments

@wladradchenko
Copy link

Hi @xinntao,

I've submitted a pull request addressing the compatibility issue mentioned in issue #768. My changes can be reviewed in the following branch: wladradchenko/Real-ESRGAN.

I’ve updated the files inference_realesrgan_video.py and inference_realesrgan.py, which are key entry points, to dynamically handle missing functions without restricting the torchvision version. With these updates, it’s possible to remove the existing limitation on torchvision (and by extension, torch), allowing users to leverage the latest versions of both torch and CUDA.

This updated code:

import sys
import types

try:
    # Check if `torchvision.transforms.functional_tensor` and `rgb_to_grayscale` are missing
    from torchvision.transforms.functional_tensor import rgb_to_grayscale
except ImportError:
    # Import `rgb_to_grayscale` from `functional` if it’s missing in `functional_tensor`
    from torchvision.transforms.functional import rgb_to_grayscale

    # Create a module for `torchvision.transforms.functional_tensor`
    functional_tensor = types.ModuleType("torchvision.transforms.functional_tensor")
    functional_tensor.rgb_to_grayscale = rgb_to_grayscale

    # Add this module to `sys.modules` so other imports can access it
    sys.modules["torchvision.transforms.functional_tensor"] = functional_tensor

Thanks for considering these improvements!

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

No branches or pull requests

1 participant