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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 162,547评论 4 374
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 68,787评论 2 308
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 112,175评论 0 254
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,752评论 0 223
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 53,169评论 3 297
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 41,056评论 1 226
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 32,195评论 2 321
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,980评论 0 214
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,724评论 1 250
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,872评论 2 254
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,344评论 1 265
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,667评论 3 264
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,379评论 3 245
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,202评论 0 9
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,992评论 0 201
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 36,189评论 2 286
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,987评论 2 279

推荐阅读更多精彩内容