【Tensorflow】非root用户安装tensorflow

因为机器权限限制,已安装了NDVI的驱动、CUDA8.0、cuDNN7.1。
但后续安装tensorflow-gpu都是坑。
如果用pip安装,不同tensorflow-gpu版本对应不同cuDNN,CUDA版本,如果强制安装,会报错各种类似libcuda.so.1包找不到


【Tensorflow】非root用户安装tensorflow_第1张图片
image.png

即使pip install tensorflow-gpu==1.1.0 降版本安装,也报错/lib64/libc.so.6: version `GLIBC_2.16' not found,需要升级系统。
to make life easy,推荐 一键构建全套的虚拟环境(需要提前安装anaconda3)

conda create --name tf_gpu tensorflow-gpu

然后通过以下命令激活和关闭环境

source activate tf_gpu
source deactivate

但是最坑爹的是该集群上activate都没有授权执行功能。
各种拜托同学后换了一个新的实验环境,CUDA10.0,cuDNN7.4。pip 可直接安装tensorflow-gpu 13.0,太方便了有没有,感慨下大清校园的资源方便。

测试

import tensorflow   
import tensorflow as tf
matrix1 = tf.constant([[3., 3.]])     
matrix2 = tf.constant([[2.],[2.]])    
product = tf.matmul(matrix1, matrix2) 
sess = tf.Session()

如果输出GPU信息,则代表安装成功,如下图

2019-03-25 14:19:52.462303: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2019-03-25 14:19:53.132123: I tensorflow/compiler/xla/service/service.cc:150] XLA service 0x55a65b582100 executing computations on platform CUDA. Devices:
2019-03-25 14:19:53.132194: I tensorflow/compiler/xla/service/service.cc:158]   StreamExecutor device (0): Tesla P100-PCIE-16GB, Compute Capability 6.0
2019-03-25 14:19:53.136793: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2300190000 Hz
2019-03-25 14:19:53.140707: I tensorflow/compiler/xla/service/service.cc:150] XLA service 0x55a65b6503f0 executing computations on platform Host. Devices:
2019-03-25 14:19:53.140747: I tensorflow/compiler/xla/service/service.cc:158]   StreamExecutor device (0): , 
2019-03-25 14:19:53.141484: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1433] Found device 0 with properties:
name: Tesla P100-PCIE-16GB major: 6 minor: 0 memoryClockRate(GHz): 1.3285
pciBusID: 0000:04:00.0
totalMemory: 15.90GiB freeMemory: 15.61GiB
2019-03-25 14:19:53.141528: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1512] Adding visible gpu devices: 0
2019-03-25 14:19:53.152529: I tensorflow/core/common_runtime/gpu/gpu_device.cc:984] Device interconnect StreamExecutor with strength 1 edge matrix:
2019-03-25 14:19:53.152579: I tensorflow/core/common_runtime/gpu/gpu_device.cc:990]      0
2019-03-25 14:19:53.152596: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1003] 0:   N
2019-03-25 14:19:53.153330: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 15190 MB memory) -> physical GPU (device: 0, name: Tesla P100-PCIE-16GB, pci bus id: 0000:04:00.0, compute capability: 6.0)

题外话:

pip安装太慢?换下镜像

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow-gpu keras 

conda下载也很慢?

conda config --add channels 'https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/'
conda config --set show_channel_urls yes

后记

良好的习惯很重要。需要构建多个虚拟环境对python开发环境进行管理。
比如virtualenv(利用pip安装软件)和anaconda自带的conda工具都可以方便构建虚拟环境。

你可能感兴趣的:(【Tensorflow】非root用户安装tensorflow)