今天在调试yolov7时遇到由题所示报错。
Traceback (most recent call last):
File "d:/1/yolov7-main/train.py", line 609, in
train(hyp, opt, device, tb_writer)
File "d:/1/yolov7-main/train.py", line 71, in train
run_id = torch.load(weights).get('wandb_id') if weights.endswith('.pt') and os.path.isfile(weights) else None
File "D:\1\envs\yolov7.2\lib\site-packages\torch\serialization.py", line 592, in load
return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
File "D:\1\envs\yolov7.2\lib\site-packages\torch\serialization.py", line 851, in _load
result = unpickler.load()
File "D:\1\envs\yolov7.2\lib\site-packages\torch\serialization.py", line 843, in persistent_load
load_tensor(data_type, size, key, _maybe_decode_ascii(location))
File "D:\1\envs\yolov7.2\lib\site-packages\torch\serialization.py", line 832, in load_tensor
loaded_storages[key] = restore_location(storage, location)
File "D:\1\envs\yolov7.2\lib\site-packages\torch\serialization.py", line 175, in default_restore_location
result = fn(storage, location)
File "D:\1\envs\yolov7.2\lib\site-packages\torch\serialization.py", line 151, in _cuda_deserialize
device = validate_cuda_device(location)
File "D:\1\envs\yolov7.2\lib\site-packages\torch\serialization.py", line 135, 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.
错误原因应该时cuda版本与显卡驱动不一致。
conda list CUDA
根据上表可以看到10.2.89所对应的显卡驱动需要>=441.22
在设备管理器中查看当前显卡驱动低于该版本,因此直接上NVIDIA官网下载驱动文件进行更新。
官方驱动 | NVIDIA
选择相应版本下载安装即可。