TencentARC / GFPGAN

GFPGAN aims at developing Practical Algorithms for Real-world Face Restoration.
Other
35.04k stars 5.8k forks source link

'torchvision.transforms.functional_tensor' has been depreciated to 'torchvision.transforms.functional' #539

Open sipsmehta opened 2 months ago

sipsmehta commented 2 months ago

Traceback (most recent call last): File "/content/GFPGAN/inference_gfpgan.py", line 7, in from basicsr.utils import imwrite File "/usr/local/lib/python3.10/dist-packages/basicsr/init.py", line 4, in from .data import * File "/usr/local/lib/python3.10/dist-packages/basicsr/data/init.py", line 22, in _dataset_modules = [importlib.import_module(f'basicsr.data.{file_name}') for file_name in dataset_filenames] File "/usr/local/lib/python3.10/dist-packages/basicsr/data/init.py", line 22, in _dataset_modules = [importlib.import_module(f'basicsr.data.{file_name}') for file_name in dataset_filenames] File "/usr/lib/python3.10/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "/usr/local/lib/python3.10/dist-packages/basicsr/data/realesrgan_dataset.py", line 11, in from basicsr.data.degradations import circular_lowpass_kernel, random_mixed_kernels File "/usr/local/lib/python3.10/dist-packages/basicsr/data/degradations.py", line 8, in from torchvision.transforms.functional_tensor import rgb_to_grayscale ModuleNotFoundError: No module named 'torchvision.transforms.functional_tensor'

shishirahm3d commented 1 month ago

@sipsmehta run this code on colab before running 3. Inference. it will replace the degradation.py line 8 from torchvision.transforms.functional_tensor import rgb_to_grayscale to: from torchvision.transforms.functional import rgb_to_grayscale

then you're good to go...

# Define the file path
file_path = '/usr/local/lib/python3.10/dist-packages/basicsr/data/degradations.py'

# Define the new import statement
new_import_statement = "from torchvision.transforms.functional import rgb_to_grayscale\n"

# Read the content of the file
with open(file_path, 'r') as file:
    lines = file.readlines()

# Modify the desired line (line 8 in this case)
if len(lines) >= 8:
    lines[7] = new_import_statement  # Index 7 corresponds to line 8 (0-based indexing)

# Write the modified content back to the file
with open(file_path, 'w') as file:
    file.writelines(lines)

print("Replacement completed successfully!")
trippyvortex commented 3 weeks ago

@shishirahm3d Thank you!