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

No module named 'torchvision.transforms.functional_tensor' #663

Closed
cncloudli opened this issue Mar 12, 2024 · 1 comment
Closed

No module named 'torchvision.transforms.functional_tensor' #663

cncloudli opened this issue Mar 12, 2024 · 1 comment

Comments

@cncloudli
Copy link

cncloudli commented Mar 12, 2024

在某些版本pytorch(2.2.1)中,torchvision.transforms.functional_tensor的名字改了,改成了torchvision.transforms._functional_tensor,导致data\degradations.py这个文件里面导入这个包时会出错,修改包名后可正常运行
In some versions of Pytorch (for example, 2.2.1), the name of the module "torchvision.transforms.functional_tensor" has been modified to "torchvision.transforms._functional_tensor", which would cause an error when import this module in the file "data\degradations.py". Editing the name of the module could solve this issue.

@neuralfalcon
Copy link

For Google Colab just copy paste this stupid code and run

import requests
import sys
import shutil
def fix():
  url = "https://raw.githubusercontent.com/neuralfalcon/DreamTalk-Colab-Demo/main/degradations.py"
  filename = "/content/degradations.py"
  full_version = sys.version.split(' ')[0]
  major_minor_version = '.'.join(full_version.split('.')[:2])
  basicsr_path=f"/usr/local/lib/python{major_minor_version}/dist-packages/basicsr/data/degradations.py"
  # Send a GET request to the URL
  response = requests.get(url)
  # Check if the request was successful (status code 200)
  if response.status_code == 200:
      # Write the content to a file
      with open(filename, 'wb') as file:
          file.write(response.content)
      try:
        shutil.copy("/content/degradations.py",basicsr_path)
        print(f"Copied to {basicsr_path}")
      except:
        print("Update the 'basicsr_path' variable -- replace '{major_minor_version}' with the current Python version in Google Colab, such as 3.10.")

  else:
      print("Failed to download the file.")
fix()

For Windows or Mac

Find python install folder then Follow the path and find degradations.py like
D:/python3.10/dist-packages/basicsr/data/degradations.py

update the line:

from torchvision.transforms.functional_tensor import rgb_to_grayscale

to:

from torchvision.transforms.functional import rgb_to_grayscale

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants