其中其决定作用的是这篇文章  https://www.pugetsystems.com/labs/hpc/Install-TensorFlow-with-GPU-Support-the-Easy-Way-on-Ubuntu-18-04-without-installing-CUDA-1170/

注意兼容版本:https://devtalk.nvidia.com/default/topic/1047898/cuda-setup-and-installation/cuda-10-1-tensorflow-1-13/2

1-安装显卡驱动

在终端执行如下命令,建议先切换到国内源,如huaweicloud mirrors。

sudo apt purge nvidia*
ubuntu-drivers devices # 可以看到显卡等设备,和推荐的驱动
sudo ubuntu-drivers autoinstall # 安装推荐驱动,通常是最新版

如果通过ubuntu-drivers devices看不到NVidia显卡,则添加

sudo add-apt-repository ppa:graphics-drivers
sudo apt-get update

安装完后,重启系统, 启动后,在图形界面运行Nvidia X Server Settings,可以看到显卡情况,如下图。

2-安装Anaconda+Tensorflow-GPU

安装 Anaconda

bash Anaconda3-5.3.0-Linux-x86_64.sh # make sure append the Anaconda executable directory to your PATH environment variable in .bashrc
source ~/.bashrc
python --version # to show the python version

装之前,推荐切换到国内源:

anaconda的源改为国内镜像, 配置文件是~/.condarc

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 --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --set show_channel_urls yes

pip源改为国内镜像, 配置文件是~/.pip/pip.conf, 该后的文件内容如下:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple/
[install]
trusted-host=https://pypi.tuna.tsinghua.edu.cn

update conda

conda update conda -y
conda update anaconda -y
conda update python -y
conda update --all -y

安装tensorflow

conda create --name tf-gpu   # Create a Python "virtual environment" for TensorFlow using conda
conda activate tf-gpu       # 注意运行此命令后,命令行开头的提示变为(tf-gpu) user@computer:~$,表示tf-gpu环境处于激活状态
# 后面的命令,都在tf-gpu环境下执行,我保留了命令行的提示,以示区别

(tf-gpu) user@computer:~$ conda install tensorflow-gpu -y # install TensorFlow with GPU acceleration and all of the dependencies.

为Tensorflow环境创建Jupyter Notebook Kernel

(tf-gpu) user@computer:~$ conda install ipykernel -y
(tf-gpu) user@computer:~$ conda install jupyter
(tf-gpu) user@computer:~$ python -m ipykernel install --user --name tf-gpu --display-name "TensorFlow-GPU"

安装keras

(tf-gpu) user@computer:~$ conda install keras -y

3-测试安装结果

用Keras 例程(Keras内部会用到Tensorflow)

打开Jupyter Notebook

jupyter notebook

创建新笔记: New下拉菜单 -> 选择TensorFlow-GPU

输入如下测试代码,并运行:

# Import dependencies
import keras
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense, Dropout
from keras.layers import Flatten, MaxPooling2D, Conv2D
from keras.callbacks import TensorBoard # Load and process the MNIST data
# 推荐先下载mnist.npz到目录~/.keras/datasets/
(X_train,y_train), (X_test, y_test) = mnist.load_data(path="mnist.npz")
X_train = X_train.reshape(60000,28,28,1).astype('float32')
X_test = X_test.reshape(10000,28,28,1).astype('float32')
X_train /= 255
X_test /= 255
n_classes = 10
y_train = keras.utils.to_categorical(y_train, n_classes)
y_test = keras.utils.to_categorical(y_test, n_classes) # Create the LeNet-5 neural network architecture
model = Sequential()
model.add(Conv2D(32, kernel_size=(3,3), activation='relu', input_shape=(28,28,1)) )
model.add(Conv2D(64, kernel_size=(3,3), activation='relu'))
model.add(MaxPooling2D(pool_size=(2,2)))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dense(128, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(n_classes, activation='softmax')) # Compile the model
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy']) # Set log data to feed to TensorBoard for visual analysis
tensor_board = TensorBoard('./logs/LeNet-MNIST-1') # Train the model
model.fit(X_train, y_train, batch_size=128, epochs=15, verbose=1,
validation_data=(X_test,y_test), callbacks=[tensor_board])

运行完后查看误差曲线

 (tf-gpu) dbk@i9:~$ tensorboard --logdir=./logs --port 6006

效果如下图

Ubuntu18.04 + NVidia显卡 + Anaconda3 + Tensorflow-GPU 安装、配置、测试 (无需手动安装CUDA)的更多相关文章

  1. Ubuntu18.04 NVIDIA显卡驱动 安装大全

    离线安装NVIDIA显卡驱动 费了一天的劲,走了好多的坑,最主要的原因是gcc版本的问题,一定要用最新版本的gcc!!! 1)官网下载显卡驱动 2)apt 下载gcc包及其依赖包,可用apt-cach ...

  2. Ubuntu16.04 Nvidia显卡驱动简明安装指南

    简单得整理了一下Ubuntu16.04 Nvidia显卡驱动的安装步骤: 查看当前系统显卡参数: sudo lspci | grep -i nvidia 删除之前的驱动: sudo apt-get - ...

  3. Hadoop2.2集群安装配置-Spark集群安装部署

    配置安装Hadoop2.2.0 部署spark 1.0的流程 一.环境描写叙述 本实验在一台Windows7-64下安装Vmware.在Vmware里安装两虚拟机分别例如以下 主机名spark1(19 ...

  4. 从subversion开始(svn安装配置全过程(+全套安装文件与配置文件))…..

    从subversion开始(svn安装配置全过程(+全套安装文件与配置文件))-.. 博客分类: 工具使用 SVNsubversion配置管理Apache应用服务器  </div> 花了一 ...

  5. MySQL 5.7.33 超级详细下载安装配置测试教程(可以安装成功版)

    目录 1.引言及注意事项 (1) 引言: (2) 注意: 2.MySQL下载 3.配置环境变量 4.配置my.ini文件(重点) 5.安装MySQL(重点) 6.设置密码 7.测试MySQL是否安装成 ...

  6. (解决某些疑难杂症)Ubuntu16.04 + NVIDIA显卡驱动 + cuda10 + cudnn 安装教程

    一.NVIDIA显卡驱动 打开终端,输入: sudo nautilus 在新打开的文件夹中,进入以下路径(不要用命令行): 左下角点计算机,lib,modules 这时会有几个文件夹,对每个文件夹都进 ...

  7. Ubuntu 14.04 Nvidia显卡驱动手动安装及设置

      更换主板修复grub 引导后,无法从Nvidia进入系统(光标闪烁), 可能是显卡驱动出了问题. 1. 进入BIOS设置, 从集成显卡进入系统 将显示器连接到集显的VGI口, 并在BIOS中设置用 ...

  8. Ubuntu 14.04 Nvidia显卡驱动安装及设置

    更换主板修复grub 引导后,无法从Nvidia进入系统(光标闪烁), 可能是显卡驱动出了问题. 1. 进入BIOS设置, 从集成显卡进入系统 将显示器连接到集显的VGI口, 并在BIOS中设置用集显 ...

  9. nginx安装配置+清缓存模块安装

    经过一段时间的使用,发现nginx在并发与负载能力方面确实优于apache,现在已经将大部分站点从apache转到了nginx了.以下是nginx的一些简单的安装配置. 环境 操作系统:CentOS. ...

随机推荐

  1. sql语句优化原理

    前言 网上有很多关于sql语句优化的文章,我这里想说下为什么这样...写sql语句,能够提高查询的效率. 1 sql语句优化原理 要想写出好的sql,就要学会用数据库的方式来思考如何执行sql,那么什 ...

  2. Nodejs 处理异步(获取异步数据并处理)的方法

    方法1. 回调函数方式 将异步方法如readFile封装到一个自定义函数中,通过将异步方法得到的结果传给自定义方法的回调函数参数.具体如下(以fs模块的readFile方法为例): //封装 var ...

  3. Tree Widget -- 基本方法

    Tree Widget这个空间类似于一种表格的形式,是一种树状结构 效果图: 第一步:打开designer.exe,拖动一个Tree Widget空间到主窗口上 第二步:双击Tree Widget,添 ...

  4. 第八篇 -- 用U盘制作启动盘装Win10系统

    下载装机吧:http://www.zhuangjiba.com 装Win10参考文章:http://www.zhuangjiba.com/bios/13249.html U盘启动盘制作 1.首先将U盘 ...

  5. python序列化proto时对repeated修饰数据进行赋值(常用类型和其他类型)

    说一下对proto文件中数据使用时的书写方法,因为笔者也经常弄混淆 一.repeated修饰符,该列表是常用类型,比如int message C2GS_GoodsList { repeated int ...

  6. 大数据学习(04)——MapReduce原理

    前两篇文章介绍了HDFS的原理和高可用,下面再来介绍Hadoop的另外一个模块MapReduce.它的思想是很多技术的鼻祖,值得一学. MapReduce是什么 MapReduce是一个分布式计算系统 ...

  7. Mac搭建Vue开发环境

    1.安装Homebrew /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/ ...

  8. dio框架访问云函数参数传递问题(以腾讯云中的云函数为例子)第一部

    dd云函数其实比较普及,这里以腾讯云的云函数为例,传递参数完成简单的账号注册. 一.第一步先注册腾讯云账号,这里不过多阐述,接着点击 控制台 进入开发者界面.(注意提前进行实名认证) 二.开发者界面如 ...

  9. 腾讯开源:Kotlin 高性能特效动画组件!

    先看一下效果展示: 1. VAP VAP(Video Animation Player)是企鹅电竞开发,用于播放酷炫动画的实现方案. 相比Webp, Apng动图方案,具有高压缩率(素材更小).硬件解 ...

  10. system V信号量和Posix信号量

    一.函数上的区别 信号量有两种实现:传统的System V信号量和新的POSIX信号量.它们所提供的函数很容易被区分:对于所有System V信号量函数,在它们的名字里面没有下划线.例如,应该是sem ...