tensorflow-gpu 环境配置流程记录

本文记录了在共享机器上配置tensorflow-gpu环境的过程,包括安装Annaconda、配置国内源以及安装tensorflow-gpu-1.12.0。由于环境特殊,未安装nvidia驱动。注意tensorflow自带的cuda9.2不适用于nvidia 390,因此选择了cuda9.1。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天第一次快速的配置好实验室机器的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)]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值