From fd9826d66cb6e58d308142271e34398b74b0eec7 Mon Sep 17 00:00:00 2001 From: Wladislav Radchenko <56233697+wladradchenko@users.noreply.github.com> Date: Sun, 27 Oct 2024 10:59:43 +0300 Subject: [PATCH 1/2] Update inference_realesrgan.py fix bug with version torchvision limit --- inference_realesrgan.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/inference_realesrgan.py b/inference_realesrgan.py index 0a8cc43ad..96004e90c 100644 --- a/inference_realesrgan.py +++ b/inference_realesrgan.py @@ -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 From 034fac022438e581ae01be69a423d48bd51df2cd Mon Sep 17 00:00:00 2001 From: Wladislav Radchenko <56233697+wladradchenko@users.noreply.github.com> Date: Sun, 27 Oct 2024 11:00:12 +0300 Subject: [PATCH 2/2] Update inference_realesrgan_video.py fix bug with version torch limit --- inference_realesrgan_video.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/inference_realesrgan_video.py b/inference_realesrgan_video.py index c3c4d1465..938dd49a9 100644 --- a/inference_realesrgan_video.py +++ b/inference_realesrgan_video.py @@ -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