Mac上TensorFlow源码编译

TensorFlow作为Google在AI领域的基础运行环境,如今作为大热门被广泛研究,这里使用Mac对TensorFlow源码进行编译。

1 安装必要的软件
1.1 安装JDK 8
JDK 8 can be downloaded from Oracle’s JDK Page : 
下载链接: (http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html)。
Look for “Mac OS X” under “Java SE Development Kit”. This will download a DMG image with an install wizard。


1.2 安装Homebrew
Install Homebrew on macOS (OS X),Installing Homebrew is a one-time setup:
$ ruby -e "(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"


1.3 安装指定版本Bazel 
安装安装Google自家的编译工具bazel。
mac上最好的办法就是直接使用brew安装了(Install Bazel Homebrew Package)
brew install bazel
You are all set. You can confirm Bazel is installed successfully by running bazel version.
You can later upgrade to newer version of Bazel with brew upgrade bazel.
由于不同版本的TensorFlow源码对于Bazel版本有自己的要求。
可以通过如下方式安装指导版本的Bazel:
进入官网: https://docs.bazel.build/versions/master/install-os-x.html
执行命令:
Step 1: Install Xcode command line tools
Xcode can be downloaded from the Apple Developer Site (this link redirects to their App Store).
For objc_* and ios_* rule support, you must have Xcode 6.1 or later with iOS SDK 8.1 installed on your system.
Once Xcode is installed, accept the license agreement for all users with the following command:
sudo xcodebuild -license accept

Step 2: Download the Bazel installer
Next, download the Bazel binary installer named bazel-<version>-installer-darwin-x86_64.sh 
from the Bazel releases page on GitHub.

Step 3: Run the installer
Run the Bazel installer as follows:
chmod +x bazel-<version>-installer-darwin-x86_64.sh
./bazel-<version>-installer-darwin-x86_64.sh --user
The --user flag installs Bazel to the $HOME/bin directory on your system and sets the .bazelrc 
path to $HOME/.bazelrc. Use the --help command to see additional installation options.
Step 4: Set up your environment
If you ran the Bazel installer with the --user flag as above, the Bazel executable is installed in your $HOME/bin directory. 
It's a good idea to add this directory to your default paths, as follows:
export PATH="PATH:PATH:PATH:HOME/bin"
You can also add this command to your ~/.bashrc or ~/.profile file.
All set! You can confirm Bazel is installed successfully by running the following command:
bazel version

1.4 Xcode安装
由于在Mac编译tensorflow需要Xcode环境。
首先打开连接: https://developer.apple.com/download/more/ 
进入页面:

在搜索框中输入 xcode 回车搜索,如下图所示:

找到所需的版本,点击+打开,查看详情,单击进行下载。
解压安装。

2 安装tensorflow
2.1 下载官方的tensorflow源码
$ git clone https://github.com/tensorflow/tensorflow

2.2 配置
下载完成之后,在用户目录下生成一个tensorflow的目录,进入这个目录。
./configure
进行配置,在配置过程中会出现一系列的问题,通常情况下没有特殊的要求,一般全部都选择n。

3 编译
配置完成后就是编译过程了,输入下面命令(输入此命令后你会发现你的电脑呼呼作响,并且会花较长时间来编译):
bazel clean --expunge
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer 这个选择Xcode的目录很重要
sudo xcodebuild -license
bazel clean --expunge
bazel build -c opt //tensorflow:libtensorflow_cc.so

4 结果
最后在bazel-bin的tensorflow下生成libtensorflow_cc.so和libtensorflow_framework.so文件。
 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值