centos7下安装部署tensorflow GPU 版本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos7下安装部署tensorflow GPU 版本相关的知识,希望对你有一定的参考价值。

系统环境:centos7



1. 安装 Python 2.7

# yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc gcc-c++ make

# download and extract Python 2.7

su hdfs

cd  ~/Downloads

curl -O https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tgz

tar -xvf Python-2.7.12.tgz


# compile into local PYTHON_ROOT

# export PYTHON_ROOT=~/Python

export PYTHON_ROOT=~/TensorFlowOnSpark-Work/Python_gpu

pushd Python-2.7.12

./configure --prefix="${PYTHON_ROOT}" --enable-unicode=ucs4 make make install popd

# install pip

pushd "${PYTHON_ROOT}" 

curl -O https://bootstrap.pypa.io/get-pip.py 

bin/python get-pip.py 

rm -rf get-pip.py


# 安装依赖库

export PYTHON_ROOT=~/TensorFlowOnSpark-Work/Python_gpu

${PYTHON_ROOT}/bin/pip install yarn-api-client

${PYTHON_ROOT}/bin/pip install uniout

${PYTHON_ROOT}/bin/pip install numpy

${PYTHON_ROOT}/bin/pip install pydoop



# 打包python_gpu

export PYTHON_ROOT=/var/lib/hadoop-hdfs/TensorFlowOnSpark-Work/Python_gpu

pushd "${PYTHON_ROOT}" zip -r Python_gpu.zip *



2. 在 Python 2.7 中安装tensorflow GPU

# 安装显卡驱动和cuda和cudda

参考文档

http://www.linuxidc.com/Linux/2016-11/137561.htm

# 安装nvidia-modprobe

yum -y install nvidia-modprobe

#查看gpu信息

export PATH="$PATH:/usr/local/cuda-8.0/bin" 

export LD_LIBRARY_PATH="/usr/local/cuda-8.0/lib64"

nvidia-smi

技术分享

能看到这个信息说明gpu已经安装配置成功


# 安装tensorflow

su hdfs

export PYTHON_ROOT=~/TensorFlowOnSpark-Work/Python_gpu

${PYTHON_ROOT}/bin/pip install tensorflow-gpu

# 安装keras

export PYTHON_ROOT=~/TensorFlowOnSpark-Work/Python_gpu

${PYTHON_ROOT}/bin/pip install keras

# 验证一 tensorflow

su hdfs

export PYTHON_ROOT=~/TensorFlowOnSpark-Work/Python_gpu

export PATH="$PATH:/usr/local/cuda-8.0/bin" 

export LD_LIBRARY_PATH="/usr/local/cuda-8.0/lib64"

${PYTHON_ROOT}/bin/python

import tensorflow as tf

hello = tf.constant(‘Hello, TensorFlow!‘)

sess = tf.Session()

print (sess.run(hello))

a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name=‘a‘)  

b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name=‘b‘)  

c = tf.matmul(a, b)  

sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))  

print(sess.run(c))  


# 验证二 tensorflow

su hdfs

cd /var/lib/hadoop-hdfs/Downloads/tensorflow/tensorflow/examples/tutorials/mnist

export PYTHON_ROOT=~/TensorFlowOnSpark-Work/Python_gpu

export PATH="$PATH:/usr/local/cuda-8.0/bin" 

export LD_LIBRARY_PATH="/usr/local/cuda-8.0/lib64"

${PYTHON_ROOT}/bin/python mnist_deep.py


技术分享

已经可以看到 gpu的进程和负载了



CUDA之nvidia-smi命令详解

http://blog.csdn.net/bruce_0712/article/details/63683787





以上是关于centos7下安装部署tensorflow GPU 版本的主要内容,如果未能解决你的问题,请参考以下文章

基于CentOS7环境的Python从3.6升级到3.8及部署Tensorflow2的过程笔记

centos7 部署jenkins

centos7 部署jenkins

centos7 部署jenkins

深度学习框架之TensorFlow的概念及安装(ubuntu下基于pip的安装,IDE为Pycharm)

CentOS7.5下安装tensorflow和运行tf-faster-rcnn