zllrunning / face-makeup.PyTorch

Lip and hair color editor using face parsing maps.
MIT License
488 stars 150 forks source link

RuntimeError: Attempted to set the storage of a tensor on device "cuda:0" to a storage on different device "cpu". #10

Open mayanktiwariiiitdmj opened 2 years ago

mayanktiwariiiitdmj commented 2 years ago

Right now the Pytorch with CUDA 10.2 is not available for the Windows OS. When I am running this project with the CUDA 11.3 for the Windows OS, then I am getting the following ERRORs.

  File "F:\Restart_08122021\my_project\module_x\test.py", line 51, in evaluate
    net = BiSeNet(n_classes=n_classes)
  File "F:\Restart_08122021\my_project\module_x\model.py", line 235, in __init__
    self.cp = ContextPath()
  File "F:\Restart_08122021\my_project\module_x\model.py", line 97, in __init__
    self.resnet = Resnet18()
  File "F:\Restart_08122021\my_project\module_x\resnet.py", line 69, in __init__
    self.init_weight()
  File "F:\Restart_08122021\my_project\module_x\resnet.py", line 83, in init_weight
    state_dict = modelzoo.load_url(resnet18_url)
  File "C:\ProgramData\Anaconda3\envs\my_project\lib\site-packages\torch\hub.py", line 595, in load_state_dict_from_url
    return torch.load(cached_file, map_location=map_location)
  File "C:\ProgramData\Anaconda3\envs\my_project\lib\site-packages\torch\serialization.py", line 713, in load
    return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
  File "C:\ProgramData\Anaconda3\envs\my_project\lib\site-packages\torch\serialization.py", line 905, in _legacy_load
    return legacy_load(f)
  File "C:\ProgramData\Anaconda3\envs\my_project\lib\site-packages\torch\serialization.py", line 841, in legacy_load
    tensor = torch.tensor([], dtype=storage.dtype).set_(
  RuntimeError: Attempted to set the storage of a tensor on device "cuda:0" to a storage on different device "cpu".  This is no longer allowed; the devices must match.

Please help me in solving this error.

vinayak015 commented 2 years ago

Could you try modifying this line: state_dict = modelzoo.load_url(resnet18_url) to state_dict = modelzoo.load_url(resnet18_url, map_location=lambda storage, loc: storage.cuda())