Ubuntu16.04+TensorFlowr1.12环境搭建指南

一、操作系统安装
OS版本:Ubuntu 16.04 (ubuntu-16.04.5-server-amd64.iso)
CPU:4Core以上
内存:4GB以上
磁盘空间:80G以上

二、基础环境准备
1、为了提高apt安装速度,更新apt为国内阿里云源
(1)复制原文件备份
sudo cp /etc/apt/source.list /etc/apt/source.list.bak
(2)编辑源列表文件
sudo vim /etc/apt/source.list
(3)将原来的列表删除,添加如下内容
deb http://mirrors.aliyun.com/ubuntu/ vivid main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ vivid-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ vivid-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ vivid-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ vivid-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ vivid main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ vivid-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ vivid-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ vivid-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ vivid-backports main restricted universe multiverse
(4)运行sudo apt-get update
2、为了提高pip安装速度,更新pip为国内阿里云源
mkdir ~/.pip
vi ~/.pip/pip.conf
编辑pip.conf文件:
[global] index-url = http://mirrors.aliyun.com/pypi/simple/
[install] trusted-host = mirrors.aliyun.com
3、安装gnome桌面(显示视频窗口需要)
sudo apt install ubuntu-gnome-desktop
4、安装git
sudo apt install git
5、加配SWAP到4GB以上(避免编译过程中分配内存失败,如果已经有超过4GB的swap空间,或者安装操作系统过程中已配置较大swap,可跳过这步)
sudo dd if=/dev/zero of=/swap bs=4096 count=1M
sudo mkswap /swap
sudo swapon /swap
sudo echo “/swap swap swap sw 0 0” >> /etc/fstab

三、安装编译工具Bazel
1、安装依赖包
sudo apt-get install pkg-config zip g++ zlib1g-dev unzip
2、下载Bazel安装包
wget https://github.com/bazelbuild/bazel/releases/download/0.18.1/bazel-0.18.1-installer-linux-x86_64.sh
3、安装Bazel
chmod +x bazel-0.18.1-installer-linux-x86_64.sh
./ bazel-0.18.1-installer-linux-x86_64.sh --user
4、设置环境变量
sudo vi ~/.bashrc
在文件最后添加:
export PATH=KaTeX parse error: Expected group after '_' at position 734: … pkg_resources/_̲_init__.py 找到:f…PATH":~/bin"
替换为:export PATH="$PATH:~/bin:/usr/lib/go-1.10/bin"
source ~/.bashrc
3、准备TensorFlow源码
git clone https://github.com/tensorflow/tensorflow.git
cd tensorflow
git checkout r1.12 # r1.9, r1.10, etc.
4、编译前测试
bazel test -c opt – //tensorflow/… -//tensorflow/compiler/… -//tensorflow/contrib/lite/…
如果告警提示支持avx、avx2、fma、sse4.1、sse4.2,则使用如下命令:
bazel test -c opt --copt=-mavx --copt=-mavx2 --copt=-mfma --copt=-msse4.1 --copt=-msse4.2 --copt=-mfpmath=both – //tensorflow/… -//tensorflow/compiler/… -//tensorflow/contrib/lite/…
5、编译配置
在tensorflow源码根目录运行:
./configure
配置如下:
在这里插入图片描述
6、Build the pip package
bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package
7、Build the package
./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
8、Install the package
pip install /tmp/tensorflow_pkg/tensorflow-version-tags.whl

参考:
https://www.tensorflow.org/install/source?hl=zh-cn
https://docs.bazel.build/versions/master/install-ubuntu.html
https://github.com/golang/go/wiki/Ubuntu

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值