Installing MXNet on OS X (Mac)

Installing MXNet on OS X (Mac)

mxnet.io/get_started/osx_setup.html

MXNet currently supports Python, R, Julia, and Scala. For users of Python on Mac, MXNet provides a set of Git Bash scripts that installs all of the required MXNet dependencies and the MXNet library.

Prepare Environment for GPU Installation

This section is optional. Skip to next section if you don’t plan to use GPUs. If you plan to build with GPU, you need to set up the environment for CUDA and cuDNN.

First, download and installCUDA 8 toolkit.

Once you have the CUDA Toolkit installed you will need to set up the required environment variables by adding the following to your ~/.bash_profile file:

exportCUDA_HOME=/usr/local/cudaexportDYLD_LIBRARY_PATH="$CUDA_HOME/lib:$DYLD_LIBRARY_PATH"exportPATH="$CUDA_HOME/bin:$PATH"

Reload ~/.bash_profile file and install dependencies:

. ~/.bash_profile? ? brew install coreutils? ? brew tap caskroom/cask

Then downloadcuDNN 5.

Unzip the file and change to the cudnn root directory. Move the header files and libraries to your local CUDA Toolkit folder:

$ sudo mv include/cudnn.h /Developer/NVIDIA/CUDA-8.0/include/? ? $ sudo mv lib/libcudnn* /Developer/NVIDIA/CUDA-8.0/lib? ? $ sudo ln -s /Developer/NVIDIA/CUDA-8.0/lib/libcudnn* /usr/local/cuda/lib/

Now we can start to build MXNet.

Quick Installation

Install MXNet for Python

Clone the MXNet source code repository to your computer and run the installation script. In addition to installing MXNet, the script installsHomebrew,Numpy,LibBLAS,OpenCV,Graphviz,NumPyandJupyter.

It takes around 5 to 10 minutes to complete the installation.

# Clone mxnet repository. In terminal, run the commands WITHOUT "sudo"git clone https://github.com/dmlc/mxnet.git ~/mxnet --recursive# If building with GPU, add configurations to config.mk file:cd~/mxnet? ? cp make/config.mk .echo"USE_CUDA=1">>config.mkecho"USE_CUDA_PATH=/usr/local/cuda">>config.mkecho"USE_CUDNN=1">>config.mk# Install MXNet for Python with all required dependenciescd~/mxnet/setup-utils? ? bash install-mxnet-osx-python.sh

You can view the installation script we just used to install MXNet for Pythonhere.

Standard installation

Installing MXNet is a two-step process:

Build the shared library from the MXNet C++ source code.

Install the supported language-specific packages for MXNet.

Note:To change the compilation options for your build, edit themake/config.mkfile and submit a build request with themakecommand.

Build the Shared Library

Install MXNet dependencies

Install the dependencies, required for MXNet, with the following commands:

Homebrew

OpenBLAS and homebrew/science (for linear algebraic operations)

OpenCV (for computer vision operations)

# Paste this command in Mac terminal to install Homebrew/usr/bin/ruby -e"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"# Insert the Homebrew directory at the top of your PATH environment variableexportPATH=/usr/local/bin:/usr/local/sbin:$PATH

brew update? ? brew install pkg-config? ? brew install graphviz? ? brew install openblas? ? brew tap homebrew/science? ? brew install opencv# For getting pipbrew install python# For visualization of network graphspip install graphviz# Jupyter notebookpip install jupyter

Build MXNet Shared Library

After you have installed the dependencies, pull the MXNet source code from Git and build MXNet to produce an MXNet library calledlibmxnet.so.

The file calledosx.mkhas the configuration required for building MXNet on OS X. First copymake/osx.mkintoconfig.mk, which is used by themakecommand:

git clone --recursive https://github.com/dmlc/mxnet ~/mxnetcd~/mxnet? ? cp make/osx.mk ./config.mkecho"USE_BLAS = openblas">> ./config.mkecho"ADD_CFLAGS += -I/usr/local/opt/openblas/include">> ./config.mkecho"ADD_LDFLAGS += -L/usr/local/opt/openblas/lib">> ./config.mkecho"ADD_LDFLAGS += -L/usr/local/lib/graphviz/">> ./config.mk? ? make -j$(sysctl -n hw.ncpu)

If building withGPUsupport, add the following configuration to config.mk and build:

echo"USE_CUDA = 1">> ./config.mkecho"USE_CUDA_PATH = /usr/local/cuda">> ./config.mkecho"USE_CUDNN = 1">> ./config.mk? ? make

Note:To change build parameters, editconfig.mk.

We have installed MXNet core library. Next, we will install MXNet interface package for the programming language of your choice:

Python

R

Julia

Scala

Install the MXNet Package for Python

Next, we install Python interface for MXNet. Assuming you are in~/mxnetdirectory, run below commands.

# Install MXNet Python packagecdpython? ? sudo python setup.py install

Check if MXNet is properly installed.

# You can change mx.cpu to mx.gpupython? ? >>> import mxnet as mx? ? >>>a=mx.nd.ones((2, 3), mx.cpu())>>> print((a * 2).asnumpy())[[2.? 2.? 2.][2.? 2.? 2.]]

If you don’t get an import error, then MXNet is ready for python.

Note: You can update mxnet for python by repeating this step after re-buildinglibmxnet.so.

Install the MXNet Package for R

You have 2 options:

Building MXNet with the Prebuilt Binary Package

Building MXNet from Source Code

Building MXNet with the Prebuilt Binary Package

For OS X (Mac) users, MXNet provides a prebuilt binary package for CPUs. The prebuilt package is updated weekly. You can install the package directly in the R console using the following commands:

install.packages("drat",repos="https://cran.rstudio.com")drat:::addRepo("dmlc")install.packages("mxnet")

Building MXNet from Source Code

Run the following commands to install the MXNet dependencies and build the MXNet R package.

Rscript-e"install.packages('devtools', repo = 'https://cran.rstudio.com')"

cdR-package? ? Rscript -e"library(devtools); library(methods); options(repos=c(CRAN='https://cran.rstudio.com')); install_deps(dependencies = TRUE)"cd..? ? make rpkg

Note:R-package is a folder in the MXNet source.

These commands create the MXNet R package as a tar.gz file that you can install as an R package. To install the R package, run the following command, use your MXNet version number:

R CMD INSTALL mxnet_current_r.tar.gz

Install the MXNet Package for Julia

The MXNet package for Julia is hosted in a separate repository, MXNet.jl, which is available onGitHub. To use Julia binding it with an existing libmxnet installation, set theMXNET_HOMEenvironment variable by running the following command:

exportMXNET_HOME=//libmxnet

The path to the existing libmxnet installation should be the root directory of libmxnet. In other words, you should be able to find thelibmxnet.sofile at$MXNET_HOME/lib. For example, if the root directory of libmxnet is~, you would run the following command:

exportMXNET_HOME=/~/libmxnet

You might want to add this command to your~/.bashrcfile. If you do, you can install the Julia package in the Julia console using the following command:

Pkg.add("MXNet")

For more details about installing and using MXNet with Julia, see theMXNet Julia documentation.

Install the MXNet Package for Scala

Before you build MXNet for Scala from source code, you must completebuilding the shared library. After you build the shared library, run the following command from the MXNet source root directory to build the MXNet Scala package:

make scalapkg

This command creates the JAR files for the assembly, core, and example modules. It also creates the native library in thenative/{your-architecture}/targetdirectory, which you can use to cooperate with the core module.

To install the MXNet Scala package into your local Maven repository, run the following command from the MXNet source root directory:

make scalainstall

Next Steps

Tutorials

How To

Architecture

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市入撒,隨后出現(xiàn)的幾起案子倔撞,更是在濱河造成了極大的恐慌慢叨,老刑警劉巖大猛,帶你破解...
    沈念sama閱讀 221,576評論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件疼进,死亡現(xiàn)場離奇詭異兰迫,居然都是意外死亡信殊,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,515評論 3 399
  • 文/潘曉璐 我一進(jìn)店門汁果,熙熙樓的掌柜王于貴愁眉苦臉地迎上來涡拘,“玉大人,你說我怎么就攤上這事据德■Γ” “怎么了?”我有些...
    開封第一講書人閱讀 168,017評論 0 360
  • 文/不壞的土叔 我叫張陵棘利,是天一觀的道長橱野。 經(jīng)常有香客問我,道長善玫,這世上最難降的妖魔是什么水援? 我笑而不...
    開封第一講書人閱讀 59,626評論 1 296
  • 正文 為了忘掉前任,我火速辦了婚禮茅郎,結(jié)果婚禮上蜗元,老公的妹妹穿的比我還像新娘。我一直安慰自己系冗,他們只是感情好奕扣,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,625評論 6 397
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著掌敬,像睡著了一般惯豆。 火紅的嫁衣襯著肌膚如雪池磁。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 52,255評論 1 308
  • 那天楷兽,我揣著相機(jī)與錄音框仔,去河邊找鬼。 笑死拄养,一個胖子當(dāng)著我的面吹牛离斩,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播瘪匿,決...
    沈念sama閱讀 40,825評論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼跛梗,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了棋弥?” 一聲冷哼從身側(cè)響起核偿,我...
    開封第一講書人閱讀 39,729評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎顽染,沒想到半個月后漾岳,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 46,271評論 1 320
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡粉寞,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,363評論 3 340
  • 正文 我和宋清朗相戀三年尼荆,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片唧垦。...
    茶點(diǎn)故事閱讀 40,498評論 1 352
  • 序言:一個原本活蹦亂跳的男人離奇死亡捅儒,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出振亮,到底是詐尸還是另有隱情巧还,我是刑警寧澤,帶...
    沈念sama閱讀 36,183評論 5 350
  • 正文 年R本政府宣布坊秸,位于F島的核電站麸祷,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏褒搔。R本人自食惡果不足惜阶牍,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,867評論 3 333
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望站超。 院中可真熱鬧荸恕,春花似錦、人聲如沸死相。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,338評論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽算撮。三九已至生宛,卻和暖如春县昂,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背陷舅。 一陣腳步聲響...
    開封第一講書人閱讀 33,458評論 1 272
  • 我被黑心中介騙來泰國打工倒彰, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人莱睁。 一個月前我還...
    沈念sama閱讀 48,906評論 3 376
  • 正文 我出身青樓待讳,卻偏偏與公主長得像,于是被迫代替她去往敵國和親仰剿。 傳聞我的和親對象是個殘疾皇子创淡,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,507評論 2 359

推薦閱讀更多精彩內(nèi)容