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 #858

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
18 changes: 18 additions & 0 deletions inference_realesrgan.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@
import cv2
import glob
import os

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

from basicsr.archs.rrdbnet_arch import RRDBNet
from basicsr.utils.download_util import load_file_from_url

Expand Down
18 changes: 18 additions & 0 deletions inference_realesrgan_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@
import shutil
import subprocess
import torch

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

from basicsr.archs.rrdbnet_arch import RRDBNet
from basicsr.utils.download_util import load_file_from_url
from os import path as osp
Expand Down