Win11极速安装Tensorflow-gpu+CUDA+cudnn

文章目录

不要使用官网版本,直接使用conda版本,有对应的包,安装很方便

0.pip/conda换默认源

为了高效下载,建议先把默认源换了,很简单这里不再赘述。(我用梯子,所以没换源😋)


cudnn7.6.0 + cuda10.1.168 +tensorflow-gpu2.3.0

1.Anaconda+python虚拟环境

如果你需要用到tensorflow了那我相信你一定会用Anaconda,Anaconda的安装不再赘述。只是提个醒,如果你第一次用conda create -n创建环境那么路径一定在C盘,而换默认路径一定是可以设置的,这里也不再展开

创建TensorFlow环境:(tf是环境名字,尽量取短点吧,要不然以后手都输麻)

python 复制代码
conda create -n tf python=3.9

2.安装CUDA以及cudnn

找到NVIDIA控制面板->帮助->系统信息->组件看一下CUDA版本,我的12.0是目前最新的,一般向下兼容

先试试cudatoolkit11.3.1和cudnn8.2.1

python 复制代码
conda search cuda


测试tensorflow的GPU版本安装成功的办法

python 复制代码
import tensorflow as tf

print('GPU',tf.test.is_gpu_available())

a = tf.constant(2.)
b = tf.constant(4.)

print(a * b)

运行结果

python 复制代码
D:\python\python.exe E:/pycharm_project2019/forward/test_gpu.py
2019-09-21 18:03:09.167168: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_100.dll
2019-09-21 18:03:12.435151: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2019-09-21 18:03:12.439660: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library nvcuda.dll
2019-09-21 18:03:12.809533: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 0 with properties: 
name: GeForce 940M major: 5 minor: 0 memoryClockRate(GHz): 0.98
pciBusID: 0000:04:00.0
2019-09-21 18:03:12.809793: I tensorflow/stream_executor/platform/default/dlopen_checker_stub.cc:25] GPU libraries are statically linked, skip dlopen check.
2019-09-21 18:03:12.814170: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1746] Adding visible gpu devices: 0
2019-09-21 18:03:24.691808: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1159] Device interconnect StreamExecutor with strength 1 edge matrix:
2019-09-21 18:03:24.692136: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1165]      0 
2019-09-21 18:03:24.692327: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1178] 0:   N 
2019-09-21 18:03:24.785375: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1304] Created TensorFlow device (/device:GPU:0 with 514 MB memory) -> physical GPU (device: 0, name: GeForce 940M, pci bus id: 0000:04:00.0, compute capability: 5.0)
GPU True
2019-09-21 18:03:24.909917: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 0 with properties: 
name: GeForce 940M major: 5 minor: 0 memoryClockRate(GHz): 0.98
pciBusID: 0000:04:00.0
2019-09-21 18:03:24.910666: I tensorflow/stream_executor/platform/default/dlopen_checker_stub.cc:25] GPU libraries are statically linked, skip dlopen check.
2019-09-21 18:03:24.927035: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1746] Adding visible gpu devices: 0
2019-09-21 18:03:24.963911: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 0 with properties: 
name: GeForce 940M major: 5 minor: 0 memoryClockRate(GHz): 0.98
pciBusID: 0000:04:00.0
2019-09-21 18:03:24.964226: I tensorflow/stream_executor/platform/default/dlopen_checker_stub.cc:25] GPU libraries are statically linked, skip dlopen check.
2019-09-21 18:03:24.968809: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1746] Adding visible gpu devices: 0
2019-09-21 18:03:24.969307: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1159] Device interconnect StreamExecutor with strength 1 edge matrix:
2019-09-21 18:03:24.969515: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1165]      0 
2019-09-21 18:03:24.969647: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1178] 0:   N 
2019-09-21 18:03:24.974380: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1304] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 514 MB memory) -> physical GPU (device: 0, name: GeForce 940M, pci bus id: 0000:04:00.0, compute capability: 5.0)
tf.Tensor(8.0, shape=(), dtype=float32)

Process finished with exit code 0

显示"GPU True",即代表GPU版本安装成功!

参考文献

1\] [Tensorflow与Python、CUDA、cuDNN的版本对应表](https://blog.csdn.net/ly869915532/article/details/124542362) 2023.10; \[2\] [Anaconda环境下Tensorflow的安装与卸载](https://blog.csdn.net/dongcjava/article/details/109524981?spm=1001.2101.3001.6661.1&utm_medium=distribute.pc_relevant_t0.none-task-blog-2~default~BlogCommendFromBaidu~Rate-1-109524981-blog-85845559.235%5Ev39%5Epc_relevant_3m_sort_dl_base1&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-2~default~BlogCommendFromBaidu~Rate-1-109524981-blog-85845559.235%5Ev39%5Epc_relevant_3m_sort_dl_base1&utm_relevant_index=1) 2020.11; \[3\] [conda 安装指定版本tensorflow cpu/gpu](https://blog.csdn.net/zdx1996/article/details/103612761) 2019.12; \[4\] [Tensorflow-gpu保姆级安装教程(Win11, Anaconda3,Python3.9)](https://blog.csdn.net/weixin_43412762/article/details/129824339)2023.3; \[5\] [在 Windows 环境中从源代码构建](https://tensorflow.google.cn/install/source_windows?hl=zh-cn); \[6\] [十分钟安装Tensorflow-gpu2.6.0+本机CUDA12 以及numpy+matplotlib各包版本协调问题](https://blog.csdn.net/Tommy_Nike/article/details/130071823) 2023.10;

相关推荐
Humbunklung23 分钟前
PySide6 GUI 学习笔记——常用类及控件使用方法(多行文本控件QTextEdit)
笔记·python·学习·pyqt
取酒鱼食--【余九】30 分钟前
rl_sar实现sim2real的整体思路
人工智能·笔记·算法·rl_sar
Jamence1 小时前
多模态大语言模型arxiv论文略读(111)
论文阅读·人工智能·语言模型·自然语言处理·论文笔记
火车叼位1 小时前
使用 uv 工具在 Windows 系统快速下载安装与切换 Python
python
归去_来兮1 小时前
图神经网络(GNN)模型的基本原理
大数据·人工智能·深度学习·图神经网络·gnn
爱吃饼干的熊猫1 小时前
PlayDiffusion上线:AI语音编辑进入“无痕时代”
人工智能·语音识别
SelectDB技术团队1 小时前
Apache Doris + MCP:Agent 时代的实时数据分析底座
人工智能·数据挖掘·数据分析·apache·mcp
Leinwin1 小时前
微软推出SQL Server 2025技术预览版,深化人工智能应用集成
人工智能·microsoft
心扬1 小时前
python网络编程
开发语言·网络·python·tcp/ip