torch.cuda.is\u available()返回True,但运行时出错,提示torch.cuda.is\u available()为false

2024-10-03 17:27:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用Cuda 10.0,torch 1.2.0 nvcc说 Cuda编译工具,10.0版,V10.0.130 NVIDIA-SMI 496.13驱动程序版本:496.13 CUDA版本:11.5

存在运行时错误

Traceback (most recent call last):
  File "demo_imitator.py", line 111, in <module>
    main()
  File "demo_imitator.py", line 102, in main
    generate_actor_result(test_opt, src_img_path)
  File "demo_imitator.py", line 44, in generate_actor_result
    imitator = Imitator(test_opt)
  File "C:\Users\dg082\Desktop\impersonator\impersonator\models\imitator.py", line 19, in __init__
    self._create_networks()
  File "C:\Users\dg082\Desktop\impersonator\impersonator\models\imitator.py", line 28, in _create_networks
    self.generator = self._create_generator().cuda()
  File "C:\Users\dg082\Desktop\impersonator\impersonator\models\imitator.py", line 59, in _create_generator
    self._load_params(net, self._opt.load_path)
  File "C:\Users\dg082\Desktop\impersonator\impersonator\models\models.py", line 173, in _load_params
    save_data = torch.load(load_path)
  File "C:\Users\dg082\.conda\envs\test\lib\site-packages\torch\serialization.py", line 386, in load
    return _load(f, map_location, pickle_module, **pickle_load_args)
  File "C:\Users\dg082\.conda\envs\test\lib\site-packages\torch\serialization.py", line 573, in _load
    result = unpickler.load()
  File "C:\Users\dg082\.conda\envs\test\lib\site-packages\torch\serialization.py", line 536, in persistent_load
    deserialized_objects[root_key] = restore_location(obj, location)
  File "C:\Users\dg082\.conda\envs\test\lib\site-packages\torch\serialization.py", line 119, in default_restore_location
    result = fn(storage, location)
  File "C:\Users\dg082\.conda\envs\test\lib\site-packages\torch\serialization.py", line 95, in _cuda_deserialize
    device = validate_cuda_device(location)
  File "C:\Users\dg082\.conda\envs\test\lib\site-packages\torch\serialization.py", line 79, in validate_cuda_device
    raise RuntimeError('Attempting to deserialize object on a CUDA '
RuntimeError: Attempting to deserialize object on a CUDA device but **torch.cuda.is_available() is False**. If you are running on a CPU-only machine, please use torch.load with map_location=torch.device('cpu') to map your storages to the CPU.

If you suspect this is an IPython 7.28.0 bug, please report it at:
    https://github.com/ipython/ipython/issues
or send an email to the mailing list at ipython-dev@python.org

You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.

Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
    %config Application.verbose_crash=True

但是我的Python说

Python 3.7.11 (default, Jul 27 2021, 09:42:29) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.cuda.is_available()
True
>>>

torch.cuda.is_available()是真的

我该怎么办


Tags: inpytestlineloadlocationtorchconda