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

ImportError: cannot import name 'get_device' from 'basicsr.utils.misc' #193

Open
aleSheng opened this issue Mar 25, 2023 · 5 comments
Open

Comments

@aleSheng
Copy link

The problem happens when the module BasicSR is imported. And Python would try to use the module instead of the file with the same name.

To solve the problem, I suggest to change the directory basicsr to another name, like cfbasicsr.

@SyedMuhammadAli
Copy link

SyedMuhammadAli commented Apr 1, 2023

In my case:
This happens if the basicsr package is already installed from the Python repo. In that case, Python tries to lookup basicsr.utils.misc from the original package (but CodeFormer has its own basicsr). The original package does not have the get_device method, but the CodeFormer version does...

@chengyu666
Copy link

chengyu666 commented Apr 6, 2023

I've met the same problem.
I resolved this problem by replacing all the
from basicsr.utils.misc import get_device
device = get_device()
with
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')

@mmosir
Copy link

mmosir commented Apr 11, 2023

A rude method is just copy the following code into the directory:basicsr\utils\misc.py

import torch
def get_device():
    if torch.cuda.is_available():
        return torch.device("cuda")
    else:
        return torch.device("cpu")

def gpu_is_available():
        return torch.cuda.is_available()

Good Luck!

@aakh1361
Copy link

A rude method is just copy the following code into the directory:basicsr\utils\misc.py

import torch
def get_device():
    if torch.cuda.is_available():
        return torch.device("cuda")
    else:
        return torch.device("cpu")

def gpu_is_available():
        return torch.cuda.is_available()

Good Luck!

I added this code to file misc.py and it worked !

@djwashout
Copy link

I did the above method but im now getting
ImportError: cannot import name 'get_device' from 'basicsr.utils.misc'

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

6 participants