Ubuntu安装tf-gpu


显卡驱动

最新的18.04.3已经可以安装430驱动

sudo apt install nvidia-driver-430

NVIDIA驱动

安装要求

官网有安装所需软件要求

安装cuda及其组件

去官网下载cuda安装runfile及其补丁

# Add NVIDIA package repository
chmod +x ./cuda_10.0.130_410.48_linux.run ./cuda_10.0.130.1_linux.run
sudo ./cuda_10.0.130_410.48_linux.run
sudo ./cuda_10.0.130.1_linux.run

注意不要重复安装nvidia显卡驱动。
然后下载cudnn.

tar -zxvf cudnn-10.0-linux-x64-v7.6.2.24.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*

然后设置环境变量(cuda安装完成时会提示)

export PATH=/usr/local/cuda/bin/:$PATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/extras/CUPTI/lib64

检验下安装

wmc@omen:~$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2018 NVIDIA Corporation
Built on Sat_Aug_25_21:08:01_CDT_2018
Cuda compilation tools, release 10.0, V10.0.130

Anaconda

Anaconda安装十分简单.去喜闻乐见的tuna下载。

chmod +x Anaconda3-2019.07-Linux-x86_64.sh
./Anaconda3-2019.07-Linux-x86_64.sh

更换anaconda和pip镜像源

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


pip install pip -U
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

安装完成后,我们使用创建一个新的python虚拟环境,安装tensorflow-gpu.

conda create -n tensor pip python=3.6
source activate tensor
pip install --upgrade tensorflow-gpu

安装jupyter插件

conda install -c conda-forge jupyter_contrib_nbextensions
jupyter contrib nbextension install --user

将conda虚拟环境作为jupyter内核

conda activate tensorflowenv
pip install ipykernel
python -m ipykernel install --user --name tensorflowenv --display-name "Python (tensorflowenv)"

示例测试

import tensorflow as tf
mnist = tf.keras.datasets.mnist

(x_train, y_train),(x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0

model = tf.keras.models.Sequential([
  tf.keras.layers.Flatten(input_shape=(28, 28)),
  tf.keras.layers.Dense(128, activation='relu'),
  tf.keras.layers.Dropout(0.2),
  tf.keras.layers.Dense(10, activation='softmax')
])

model.compile(optimizer='adam',
              loss='sparse_categorical_crossentropy',
              metrics=['accuracy'])

model.fit(x_train, y_train, epochs=5)
model.evaluate(x_test, y_test)

运行结果


文章作者: 彰寒
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 彰寒 !
评论
 上一篇
深度学习:BP算法 深度学习:BP算法
神经网络正向及反向传播核心算法 Logistics regression作业import numpy as np import matplotlib.pyplot as plt import matplotlib import h5py f
2019-03-09
下一篇 
CS:APP I/O_lab CS:APP I/O_lab
实验步骤本次试验中,主要涉及keyboard.S,tty_io.c,console.c。其中:keyboard.S主要实现键盘中断处理过程,当按下键盘时,出发中断,由对应函数进行处理,并将字符放入read_q写队列中;tty_io.c包含t
2018-12-28
  目录