【深度学习GPU】Anaconda最速搭建tensorflow2-gpu+keras-gpu环境+ jupyternotebook新手配置
网上什么自己下cuda和cudnn太磨叽了,anaconda自己就可以安.
目录:
1.以管理员身份运行Anaconda Prompt
2. 换清华源
换国内源可以加速下载,步骤如下:
(1)先在小黑框中输入以下命令,运行一次conda config可以生成.condarc文件
conda config --show channels
(2)去 User/ 用户名 文件夹下找到 .condarc文件
(3)用记事本方式打开后,将以下内容复制粘贴进去,替换掉原来内容
channels:
- defaults
show_channel_urls: true
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
custom_channels:
conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
执行conda install xxx时, 会依次从default_channels中的路径查找xxx包。custom_channels是专用路径,比如想要安装pytorch相关的包,可以采用命令conda install -c pytorch pytorch torchvision,其中-c pytorch就是指定了pytorch路径。
3. 将python3.8降级成3.7(自选)
conda install python=3.7 anaconda=custom
4. 安装tensorflow-gpu2
conda install tensorflow-gpu=2.3.0
(版本号自选)
之后可以进行测试是否安装成功:
1.输入python
2.输入以下命令查看安装是否成功
import tensorflow as tf
from tensorflow.keras import layers
print(tf.__version__)
print(tf.keras.__version__)
(最后可以用exit()来退出python模式)
环境搭建到此为止,剩下的根据需要选择阅读
5. 安完后可以弄弄jupyter-notebook
5.1 更换主题和配置扩展插件(代码补全等)
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
pip install jupyterthemes
pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install --user
jupyterthemes是主题, jupyter_contrib_nbextensions是插件扩展
想换主题的话推荐两款:(一样在Anaconda Prompt中输入命令)
亮色:
jt -t grade3 -T -f source -tf robotosans -tfs 12 -nf robotosans -nfs 13 -cellw 90%
暗色:
jt -t oceans16 -T -f source -tf robotosans -tfs 12 -nf robotosans -nfs 13 -cellw 90%
想开一些插件的话
你会发现多出了这个选项
下面是我选择开启的几个插件
Hinterland是代码补全(烂的一批), ScrollDown是让输出有滚动条, Table of Contents可以让代码有一个目录, Variable Inspector是变量表.
5.2 更换jupyter工作目录
打开jupyter之后,显示的页面就是你的工作目录,肯定都不想用默认的工作目录。
- 打开快捷方式所在位置
- 右键属性,找到目标中的%USERPROFILE%字样
- 替换成你的工作目录
- 想图方便可以把快捷方式直接复制到桌面上
最后, 这个博客有tensorflow2的教程,适合新手入门:https://blog.csdn.net/qq_31456593/article/details/88377117