超简单三步安装最新深度学习环境 Ubuntu18.04 Cuda

2019-05-27  本文已影响0人  _龙雀

0. 装系统 Ubuntu 18.04

1. 安装anaconda

2. 安装RTX 2070驱动

该方法理论上可以自动匹配到任意nvidia显卡最新驱动并进行下载安装

参考 https://caltong.com/158

sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update
ubuntu-drivers devices

这时候会出现几个显卡驱动型号


image.png

选择recommended那个版本进行安装 这个过程会比较久

sudo apt-get install nvidia-driver-430

安装完成后重启电脑 输入以下指令 确认显卡驱动是否安装成功

nvidia-smi
image.png

3. 安装tensorflow-gpu

输入conda install tensorflow-gpu,会自动索引到最新版本的tensorflow-gpu以及对应版本的cudnn

image.png

成功!

首先测试tf

import tensorflow as tf
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))

查看log是否有gpu相关信息

应该是keras的更新速度跟不上tensorflow的问题,网上说主动降级tensorflow到1.18 1.19的都有,这都不是好的解决办法。tensorflow降级需要同时改变cudnn的版本。
目前我找到的方便的解决方法是 每次在调用keras之前执行以下代码

import tensorflow as tf
from tensorflow import keras
config = tf.ConfigProto()
config.gpu_options.allow_growth = True
sess = tf.Session(config = config)
keras.backend.set_session(sess)

cpu vs gpu 测试代码 https://databricks.com/tensorflow/using-a-gpu
shape的值设置的越大,速度差距越明显

import sys
import numpy as np
import tensorflow as tf
from datetime import datetime

device_name = sys.argv[1]  # Choose device from cmd line. Options: gpu or cpu
shape = (int(sys.argv[2]), int(sys.argv[2]))
if device_name == "gpu":
    device_name = "/gpu:0"
else:
    device_name = "/cpu:0"

with tf.device(device_name):
    random_matrix = tf.random_uniform(shape=shape, minval=0, maxval=1)
    dot_operation = tf.matmul(random_matrix, tf.transpose(random_matrix))
    sum_operation = tf.reduce_sum(dot_operation)


startTime = datetime.now()
with tf.Session(config=tf.ConfigProto(log_device_placement=True)) as session:
        result = session.run(sum_operation)
        print(result)

# It can be hard to see the results on the terminal with lots of output -- add some newlines to improve readability.
print("\n" * 5)
print("Shape:", shape, "Device:", device_name)
print("Time taken:", datetime.now() - startTime)

print("\n" * 5)

参考:https://www.cnblogs.com/qingspace/p/6672077.html

sudo wget http://www.linuxidc.com/files/repo/google-chrome.list -P /etc/apt/sources.list.d/

sudo apt update

wget -q -O - https://dl.google.com/linux/linux_signing_key.pub  | sudo apt-key add -

apt install google-chrome-stable
#这里下载64位
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb

sudo dpkg -i google-chrome-stable_current_amd64.deb

参考文档:

https://caltong.com/158
https://github.com/moritzhambach/CPU-vs-GPU-benchmark-on-MNIST
https://caltong.com/158
https://www.liangzl.com/get-article-detail-12148.html

上一篇下一篇

猜你喜欢

热点阅读