01_Windows11+TensorFlow2 GPU版:AI加速度,让电脑秒变智能小超人!

在这里插入图片描述

1. Tensorflow2.x-GPU 安装

各位科技探险家们,你们是不是也曾幻想过,让Windows 11这位时尚界的新贵,与TensorFlow 2这位AI界的魔术师,在GPU这个超级舞台上携手共舞?别急着摇头,这可不是科幻小说的桥段,而是一场即将在你电脑里上演的“跨界合作”!想象一下,安装过程就像是在为一场宇宙级盛宴布置餐桌,既得保证Windows 11这位挑剔的贵客满意,又得让TensorFlow 2这位魔法大厨能大展拳脚,在GPU那无尽的算力海洋里烹饪出最美味的数据大餐。别担心,接下来的教程,咱们就一起化繁为简,让这场“安装盛宴”变得既有趣又轻松,保证让你的电脑秒变AI界的超级英雄!

1.1 下载安装包

在网站 Tensorflow 官网:https://tensorflow.google.cn/install/source_windows?hl=en#gpu ,想要在Windows下使用GPU跑深度学习模型,需要使用tensorflow-gpu,其目前最高版本是2.10.0。GPU 支持在本地-Windows 只支持2.10或更早的版本,从 TF 2.11开始,CUDA build 不支持 Windows。

在这里插入图片描述

1.2 修改镜像地址

  • 修改 Anaconda 默认源镜像地址
#用清华conda 镜像

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/  
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/  
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/  
conda config --append channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/fastai/  
conda config --append channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/  
conda config --append channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/  

#搜索时显示通道地址

conda config --set show_channel_urls yes

也可以直接修改:C:\Users\用户名 目录下的 .condarc 文件

在这里插入图片描述

1.3 安装 CUDA 环境

  • 安装 GPU 版本的 Tensorflow 需要先安装 CUDA 环境

详细查看《Windows11_CUDA安装》

  • 查看所有虚拟环境

使用超级管理员,打开 Anaconda Prompt

conda info --envs  
conda env list

在这里插入图片描述

1.4 创建虚拟环境

conda create -n tensorflow_gpu python=3.10

在这里插入图片描述

  • 激活虚拟环境
activate tensorflow_gpu

在这里插入图片描述

  • 指定安装 tensorflow 版本为2.10.0 (Windows 只支持2.10或更早的版本,从 TF 2.11开始,CUDA build 不支持 Windows)
pip install tensorflow-gpu==2.10.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

在这里插入图片描述

  • 安装成功

在这里插入图片描述

2. 验证是否安装成功

  • 在虚拟环境下进入python交互页面
python   
import tensorflow as tf  
print(tf.\__version__) #tensorflow版本  
print('GPU', tf.test.is_gpu_available()) #gpu  

在这里插入图片描述

  • 退出

在这里插入图片描述

  • 退出当前的虚拟环境

在这里插入图片描述

  • 使用 CMD 校验,cd 进入到cuda的安装路径(比如我的就是 C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2),并继续向下进入到extras\demo_suite 文件夹,找到如下两个.exe文件,并在cmd窗口内执行,看是否得出如下图所示的结果:

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

3. 将 tensorflow_gpu 虚拟环境添加到 jupyter notebook

要想在 jupyter notebook 使用 tensorflow_gpu 虚拟环境,首先要将 tensorflow_gpu 虚拟环境加到 jupyter notebook,这样就可以在 jupyter notebook 里进行切换

  • 使用超级管理员,打开 Anaconda Prompt,激活 tensorflow_gpu 虚拟环境
conda activate tensorflow_gpu

在这里插入图片描述

  • 安装ipykernel包
pip install ipykernel -i https://pypi.tuna.tsinghua.edu.cn/simple
  • 开始安装

在这里插入图片描述

  • 安装完成

在这里插入图片描述

  • 添加新环境到 Jupyter Notebook,使用 ipykernel 将新环境添加到 Jupyter Notebook 的内核列表中。你可以为这个内核指定一个名称,例如:Python 3 (tensorflow_gpu)
python -m ipykernel install --user --name tensorflow_gpu --display-name "Python 3 (tensorflow_gpu)"

在这里插入图片描述

  • jupyter notebook 里切换到 Python 3 (tensorflow_gpu) 虚拟环境

在这里插入图片描述

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

腾飞开源

你的鼓励将是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值