今天第一次快速的配置好实验室机器的tensorflow-gpu环境,写下这篇博客来记录一下
1. 安装Annaconda
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-5.3.1-Linux-x86_64.sh
bash Anaconda3-5.3.1-Linux-x86_64.sh
2. 配置国内源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
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/cloud/msys2/
# 设置搜索时显示通道地址
conda config --set show_channel_urls yes
3. 安装tensorflow-gpu-1.12.0
conda install tensorflow-gpu=1.12.0
由于是共享的机器,不需要安装nvidia驱动
- 安装tenesorflow的时候自带的cuda9.2对于nvidia 390来说版本过于高,所以需要重新下载cuda9.1:
#版本对应:https://www.jianshu.com/p/c9230101a272
conda install cudatoolkit=9.0 -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/linux-64/
- 用下列代码进行测试:
import tensorflow as tf
with tf.device('/cpu:0'):
a = tf.constant([1.0,2.0,3.0],shape=[3],name='a')
b = tf.constant([1.0,2.0,3.0],shape=[3],name='b')
with tf.device('/gpu:1'):
c = a+b
sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True,log_device_placement=True))
sess.run(tf.global_variables_initializer())
print(sess.run(c))
输出如下:
(tf) liuhaohe@pc-pc:~$ ls
anaconda3 Anaconda3-5.3.1-Linux-x86_64.sh examples.desktop gpu_test.py
(tf) liuhaohe@pc-pc:~$ python gpu_test.py
/home/disk2/internship_anytime/liuhaohe/anaconda3/envs/tf/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:523: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint8 = np.dtype([("qint8", np.int8, 1)]