今天打算学习一下简单的深度学习模型,然后在网上找了一段简单的代码

找的代码网站如下:Pytorch实战1:LeNet手写数字识别 (MNIST数据集)_sunqiande88的博客-CSDN博客

复制拷贝之后在 VSCode 上面运行发现出了下面这个错误

PS D:\vscode\code> python day1013.py
D:\Anaconda3\File\lib\site-packages\torchvision\datasets\mnist.py:498: UserWarning: The given NumPy array is not writeable, and PyTorch does not support non-writeable tensors. This means you can write to the underlying (supposedly non-writeable) NumPy array using the tensor. You may want to copy the array to protect its data or make it writeable before converting it to a tensor. This type of warning will be suppressed for the rest of this program. (Triggered internally at  ..\torch\csrc\utils\tensor_numpy.cpp:180.)
  return torch.from_numpy(parsed.astype(m[2], copy=False)).view(*s)
D:\Anaconda3\File\lib\site-packages\torch\cuda\__init__.py:106: UserWarning:
NVIDIA GeForce RTX 3060 Laptop GPU with CUDA capability sm_86 is not compatible with the current PyTorch installation.       
The current PyTorch install supports CUDA capabilities sm_37 sm_50 sm_60 sm_61 sm_70 sm_75 compute_37.
If you want to use the NVIDIA GeForce RTX 3060 Laptop GPU GPU with PyTorch, please check the instructions at https://pytorch.org/get-started/locally/

  warnings.warn(incompatible_device_warn.format(device_name, capability, " ".join(arch_list), device_name))

满是愁苦,仿佛今天一天都不好了,然后仔细分析原因,看报错上面说的是

NVIDIA GeForce RTX 3060 Laptop GPU with CUDA capability sm_86 is not compatible with the current PyTorch installation.       

大概意思是  3060的显卡和我安装的CUDA版本与我安装的pytorch版本不兼容,然后我仔细查每个东西的版本,其中参考了下面的这个博客,分析是否我的环境存在版本冲突

Pytorch版本、CUDA版本与显卡驱动版本的对应关系_kelly若的博客-CSDN博客

开始其中查询各个部分的版本   

首先是  查询  torch版本 使用下面的命令 

  1. import torch

  2. print(torch.__version__) #注意是双下划线

接着查询 CUDA和cudnn的版本型号

使用  nvcc -V 命令

 也可以通过 conda list 命令 查询所有anaconda 中各个库的版本

 然后看到上面我发现报错的问题确实是我的 cuda 版本和 cudnn 的版本与 pytorch的版本不兼容

我安装的  pytorch版本是1.9.1 只支持 cuda10.2的版本,但是上面可以看到我安装的cuda版本是11.4版本的,所以我在dos里面用pip命令去卸载了 torch

pip uninstall torch

然后再  pytorch 官网中使用官网给的命令重新安装了最新11版本的pytorch

最后问题解决,代码成功运行

 最后谢谢大家观看和参考我的技术博客,不过本博主技术很菜,如果我又哪里写的不对的或者更复杂的东西欢迎大佬们在评论区留言讨论,希望大家可以共同进步,谢谢

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐