CodeFormer
CodeFormer copied to clipboard
ImportError: cannot import name 'get_device' from 'basicsr.utils.misc'
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.
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...
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')
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!
A rude method is just copy the following code into the directory:
basicsr\utils\misc.pyimport 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 !
I did the above method but im now getting ImportError: cannot import name 'get_device' from 'basicsr.utils.misc'