- 初始化环境
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y build-essential git python-pip libfreetype6-dev libxft-dev libncurses-dev libopenblas-dev gfortran python-matplotlib libblas-dev liblapack-dev libatlas-base-dev python-dev python-pydot linux-headers-generic linux-image-extra-virtual unzip python-numpy swig python-pandas python-sklearn unzip wget pkg-config zip g++ zlib1g-dev
- 下载 cuda [注:tensorflow-gpu当前pip安装版本1.9,支持cuda9.0+cudnn7.1.4for cuda9.0
http://developer.download.nvidia.com/compute/cuda/repos/ 选择对应系统版本,本次使用cuda9
sudo dpkg -i cuda-repo-ubuntu1410_XXXX_amd64.deb
rm cuda-repo-ubuntu1410_XXXX_amd64.deb
sudo apt-get update
sudo apt-get install -y cuda
安装错误卸载 sudo dpkg -P packagename, sudo apt-get autoremove cuda
- 下载cudnn
https://developer.nvidia.com/rdp/cudnn-archive
选择 cuDNN vXXX Library for Linux,目前下载cudnn7.1.4 for cuda9.0
cp cudnn-XXX.solitairetheme8 cudnn-linux-x64.tgz
tar -xvf cudnn-linux-x64.tgz
sudo cp cuda/include/cudnn.h /usr/local/cuda/include
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*
- 配置环境变量
sudo vi ~/.bashrc
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64"
export CUDA_HOME=/usr/local/cuda
export PATH="$CUDA_HOME/bin:$PATH"
source ~/.bashrc
- 安装tensorflow-gpu == 1.9
pip install keras
pip install tensorflow-gpu==1.9
- 安装运行
import tensorflow as tf
提示
h5py numpy警告
pip install h5py==2.8.0rc1