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

Open
opened 2026-01-29 21:48:05 +00:00 by claunia · 4 comments
Owner

Originally created by @sipsmehta on GitHub (May 1, 2024).

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'

Originally created by @sipsmehta on GitHub (May 1, 2024). Traceback (most recent call last): File "/content/GFPGAN/inference_gfpgan.py", line 7, in <module> from basicsr.utils import imwrite File "/usr/local/lib/python3.10/dist-packages/basicsr/__init__.py", line 4, in <module> from .data import * File "/usr/local/lib/python3.10/dist-packages/basicsr/data/__init__.py", line 22, in <module> _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 <listcomp> _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 <module> 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 <module> from torchvision.transforms.functional_tensor import rgb_to_grayscale ModuleNotFoundError: No module named 'torchvision.transforms.functional_tensor'
Author
Owner

@shishirahm3d commented on GitHub (May 16, 2024):

@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!")
@shishirahm3d commented on GitHub (May 16, 2024): @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!") ```
Author
Owner

@trippyvortex commented on GitHub (Jun 5, 2024):

@shishirahm3d Thank you!

@trippyvortex commented on GitHub (Jun 5, 2024): @shishirahm3d Thank you!
Author
Owner

@Afsalts commented on GitHub (Aug 9, 2024):

@shishirahm3d
i have a doubt. can i train the model on side faces . so it can enhance that. since now it dont work properluy on side faces

@Afsalts commented on GitHub (Aug 9, 2024): @shishirahm3d i have a doubt. can i train the model on side faces . so it can enhance that. since now it dont work properluy on side faces
Author
Owner

@WoodyBuendia commented on GitHub (Sep 23, 2024):

@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!")

It is realy helpful,ths!

@WoodyBuendia commented on GitHub (Sep 23, 2024): > @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!") > ``` It is realy helpful,ths!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: TencentARC/GFPGAN#479