Not working with pytorch 2.* #504

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

Originally created by @rvgurijala on GitHub (Aug 11, 2024).

Not working with pytorch 2.*

error:
ModuleNotFoundError: No module named 'torchvision.transforms.functional_tensor'

Originally created by @rvgurijala on GitHub (Aug 11, 2024). Not working with pytorch 2.* error: ModuleNotFoundError: No module named 'torchvision.transforms.functional_tensor'
Author
Owner

@shishirahm3d commented on GitHub (Aug 21, 2024):

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

# 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 (Aug 21, 2024): 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 ``` # 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

@hjj-lmx commented on GitHub (Sep 5, 2024):

请问怎么解决的

@hjj-lmx commented on GitHub (Sep 5, 2024): 请问怎么解决的
Author
Owner

@zolon-manoo commented on GitHub (Jun 11, 2025):

maybe you can try as this

@zolon-manoo commented on GitHub (Jun 11, 2025): maybe you can try as [this](https://github.com/xinntao/Real-ESRGAN/issues/768#issuecomment-2439896571)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: TencentARC/GFPGAN#504