versions/0.11.0/get_started/build_from_source.html (557 lines of code) (raw):

<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"/> <meta content="IE=edge" http-equiv="X-UA-Compatible"/> <meta content="width=device-width, initial-scale=1" name="viewport"/> <meta content="Build MXNet from Source" property="og:title"> <meta content="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/image/og-logo.png" property="og:image"> <meta content="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/image/og-logo.png" property="og:image:secure_url"> <meta content="Build MXNet from Source" property="og:description"/> <title>Build MXNet from Source — mxnet documentation</title> <link crossorigin="anonymous" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" rel="stylesheet"/> <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet"/> <link href="../_static/basic.css" rel="stylesheet" type="text/css"> <link href="../_static/pygments.css" rel="stylesheet" type="text/css"> <link href="../_static/mxnet.css" rel="stylesheet" type="text/css"/> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: '../', VERSION: '', COLLAPSE_INDEX: false, FILE_SUFFIX: '.html', HAS_SOURCE: true, SOURCELINK_SUFFIX: '.txt' }; </script> <script src="https://code.jquery.com/jquery-1.11.1.min.js" type="text/javascript"></script> <script src="../_static/underscore.js" type="text/javascript"></script> <script src="../_static/searchtools_custom.js" type="text/javascript"></script> <script src="../_static/doctools.js" type="text/javascript"></script> <script src="../_static/selectlang.js" type="text/javascript"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"></script> <script type="text/javascript"> jQuery(function() { Search.loadIndex("/versions/0.11.0/searchindex.js"); Search.init();}); </script> <!-- --> <!-- <script type="text/javascript" src="../_static/jquery.js"></script> --> <!-- --> <!-- <script type="text/javascript" src="../_static/underscore.js"></script> --> <!-- --> <!-- <script type="text/javascript" src="../_static/doctools.js"></script> --> <!-- --> <!-- <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> --> <!-- --> <link href="../genindex.html" rel="index" title="Index"> <link href="../search.html" rel="search" title="Search"/> <link href="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/image/mxnet-icon.png" rel="icon" type="image/png"/> </link></link></link></meta></meta></meta></head> <body background="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/image/mxnet-background-compressed.jpeg" role="document"> <div class="content-block"><div class="navbar navbar-fixed-top"> <div class="container" id="navContainer"> <div class="innder" id="header-inner"> <h1 id="logo-wrap"> <a href="../" id="logo"><img src="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/image/mxnet_logo.png"/></a> </h1> <nav class="nav-bar" id="main-nav"> <a class="main-nav-link" href="/versions/0.11.0/get_started/install.html">Install</a> <span id="dropdown-menu-position-anchor"> <a aria-expanded="true" aria-haspopup="true" class="main-nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button">Gluon <span class="caret"></span></a> <ul class="dropdown-menu navbar-menu" id="package-dropdown-menu"> <li><a class="main-nav-link" href="/versions/0.11.0/tutorials/gluon/gluon.html">About</a></li> <li><a class="main-nav-link" href="https://www.d2l.ai/">Dive into Deep Learning</a></li> <li><a class="main-nav-link" href="https://gluon-cv.mxnet.io">GluonCV Toolkit</a></li> <li><a class="main-nav-link" href="https://gluon-nlp.mxnet.io/">GluonNLP Toolkit</a></li> </ul> </span> <span id="dropdown-menu-position-anchor"> <a aria-expanded="true" aria-haspopup="true" class="main-nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button">API <span class="caret"></span></a> <ul class="dropdown-menu navbar-menu" id="package-dropdown-menu"> <li><a class="main-nav-link" href="/versions/0.11.0/api/python/index.html">Python</a></li> <li><a class="main-nav-link" href="/versions/0.11.0/api/c++/index.html">C++</a></li> <li><a class="main-nav-link" href="/versions/0.11.0/api/julia/index.html">Julia</a></li> <li><a class="main-nav-link" href="/versions/0.11.0/api/perl/index.html">Perl</a></li> <li><a class="main-nav-link" href="/versions/0.11.0/api/r/index.html">R</a></li> <li><a class="main-nav-link" href="/versions/0.11.0/api/scala/index.html">Scala</a></li> </ul> </span> <span id="dropdown-menu-position-anchor-docs"> <a aria-expanded="true" aria-haspopup="true" class="main-nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button">Docs <span class="caret"></span></a> <ul class="dropdown-menu navbar-menu" id="package-dropdown-menu-docs"> <li><a class="main-nav-link" href="/versions/0.11.0/how_to/faq.html">FAQ</a></li> <li><a class="main-nav-link" href="/versions/0.11.0/tutorials/index.html">Tutorials</a> <li><a class="main-nav-link" href="https://github.com/apache/incubator-mxnet/tree/v0.11.0/example">Examples</a></li> <li><a class="main-nav-link" href="/versions/0.11.0/architecture/index.html">Architecture</a></li> <li><a class="main-nav-link" href="https://cwiki.apache.org/confluence/display/MXNET/Apache+MXNet+Home">Developer Wiki</a></li> <li><a class="main-nav-link" href="/versions/0.11.0/model_zoo/index.html">Model Zoo</a></li> <li><a class="main-nav-link" href="https://github.com/onnx/onnx-mxnet">ONNX</a></li> </li></ul> </span> <span id="dropdown-menu-position-anchor-community"> <a aria-expanded="true" aria-haspopup="true" class="main-nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button">Community <span class="caret"></span></a> <ul class="dropdown-menu navbar-menu" id="package-dropdown-menu-community"> <li><a class="main-nav-link" href="http://discuss.mxnet.io">Forum</a></li> <li><a class="main-nav-link" href="https://github.com/apache/incubator-mxnet/tree/v0.11.0">Github</a></li> <li><a class="main-nav-link" href="/versions/0.11.0/community/contribute.html">Contribute</a></li> </ul> </span> <span id="dropdown-menu-position-anchor-version" style="position: relative"><a href="#" class="main-nav-link dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="true">0.11.0<span class="caret"></span></a><ul id="package-dropdown-menu" class="dropdown-menu"><li><a href="/">master</a></li><li><a href="/versions/1.7.0/">1.7.0</a></li><li><a href=/versions/1.6.0/>1.6.0</a></li><li><a href=/versions/1.5.0/>1.5.0</a></li><li><a href=/versions/1.4.1/>1.4.1</a></li><li><a href=/versions/1.3.1/>1.3.1</a></li><li><a href=/versions/1.2.1/>1.2.1</a></li><li><a href=/versions/1.1.0/>1.1.0</a></li><li><a href=/versions/1.0.0/>1.0.0</a></li><li><a href=/versions/0.12.1/>0.12.1</a></li><li><a href=/versions/0.11.0/>0.11.0</a></li></ul></span></nav> <script> function getRootPath(){ return "../" } </script> <div class="burgerIcon dropdown"> <a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button">☰</a> <ul class="dropdown-menu" id="burgerMenu"> <li><a href="/versions/0.11.0/get_started/install.html">Install</a></li> <li><a class="main-nav-link" href="/versions/0.11.0/tutorials/index.html">Tutorials</a></li> <li class="dropdown-submenu dropdown"> <a aria-expanded="true" aria-haspopup="true" class="dropdown-toggle burger-link" data-toggle="dropdown" href="#" tabindex="-1">Gluon</a> <ul class="dropdown-menu navbar-menu" id="package-dropdown-menu"> <li><a class="main-nav-link" href="/versions/0.11.0/tutorials/gluon/gluon.html">About</a></li> <li><a class="main-nav-link" href="http://gluon.mxnet.io">The Straight Dope (Tutorials)</a></li> <li><a class="main-nav-link" href="https://gluon-cv.mxnet.io">GluonCV Toolkit</a></li> <li><a class="main-nav-link" href="https://gluon-nlp.mxnet.io/">GluonNLP Toolkit</a></li> </ul> </li> <li class="dropdown-submenu"> <a aria-expanded="true" aria-haspopup="true" class="dropdown-toggle burger-link" data-toggle="dropdown" href="#" tabindex="-1">API</a> <ul class="dropdown-menu"> <li><a class="main-nav-link" href="/versions/0.11.0/api/python/index.html">Python</a></li> <li><a class="main-nav-link" href="/versions/0.11.0/api/c++/index.html">C++</a></li> <li><a class="main-nav-link" href="/versions/0.11.0/api/julia/index.html">Julia</a></li> <li><a class="main-nav-link" href="/versions/0.11.0/api/perl/index.html">Perl</a></li> <li><a class="main-nav-link" href="/versions/0.11.0/api/r/index.html">R</a></li> <li><a class="main-nav-link" href="/versions/0.11.0/api/scala/index.html">Scala</a></li> </ul> </li> <li class="dropdown-submenu"> <a aria-expanded="true" aria-haspopup="true" class="dropdown-toggle burger-link" data-toggle="dropdown" href="#" tabindex="-1">Docs</a> <ul class="dropdown-menu"> <li><a href="/versions/0.11.0/how_to/faq.html" tabindex="-1">FAQ</a></li> <li><a href="/versions/0.11.0/tutorials/index.html" tabindex="-1">Tutorials</a></li> <li><a href="https://github.com/apache/incubator-mxnet/tree/v0.11.0/example" tabindex="-1">Examples</a></li> <li><a href="/versions/0.11.0/architecture/index.html" tabindex="-1">Architecture</a></li> <li><a href="https://cwiki.apache.org/confluence/display/MXNET/Apache+MXNet+Home" tabindex="-1">Developer Wiki</a></li> <li><a href="/versions/0.11.0/model_zoo/index.html" tabindex="-1">Gluon Model Zoo</a></li> <li><a href="https://github.com/onnx/onnx-mxnet" tabindex="-1">ONNX</a></li> </ul> </li> <li class="dropdown-submenu dropdown"> <a aria-haspopup="true" class="dropdown-toggle burger-link" data-toggle="dropdown" href="#" role="button" tabindex="-1">Community</a> <ul class="dropdown-menu"> <li><a href="http://discuss.mxnet.io" tabindex="-1">Forum</a></li> <li><a href="https://github.com/apache/incubator-mxnet/tree/v0.11.0" tabindex="-1">Github</a></li> <li><a href="/versions/0.11.0/community/contribute.html" tabindex="-1">Contribute</a></li> </ul> </li> <li id="dropdown-menu-position-anchor-version-mobile" class="dropdown-submenu" style="position: relative"><a href="#" tabindex="-1">0.11.0</a><ul class="dropdown-menu"><li><a tabindex="-1" href=/>master</a></li><li><a tabindex="-1" href=/versions/1.6.0/>1.6.0</a></li><li><a tabindex="-1" href=/versions/1.5.0/>1.5.0</a></li><li><a tabindex="-1" href=/versions/1.4.1/>1.4.1</a></li><li><a tabindex="-1" href=/versions/1.3.1/>1.3.1</a></li><li><a tabindex="-1" href=/versions/1.2.1/>1.2.1</a></li><li><a tabindex="-1" href=/versions/1.1.0/>1.1.0</a></li><li><a tabindex="-1" href=/versions/1.0.0/>1.0.0</a></li><li><a tabindex="-1" href=/versions/0.12.1/>0.12.1</a></li><li><a tabindex="-1" href=/versions/0.11.0/>0.11.0</a></li></ul></li></ul> </div> <div class="plusIcon dropdown"> <a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button"><span aria-hidden="true" class="glyphicon glyphicon-plus"></span></a> <ul class="dropdown-menu dropdown-menu-right" id="plusMenu"></ul> </div> <div id="search-input-wrap"> <form action="../search.html" autocomplete="off" class="" method="get" role="search"> <div class="form-group inner-addon left-addon"> <i class="glyphicon glyphicon-search"></i> <input class="form-control" name="q" placeholder="Search" type="text"/> </div> <input name="check_keywords" type="hidden" value="yes"> <input name="area" type="hidden" value="default"/> </input></form> <div id="search-preview"></div> </div> <div id="searchIcon"> <span aria-hidden="true" class="glyphicon glyphicon-search"></span> </div> <!-- <div id="lang-select-wrap"> --> <!-- <label id="lang-select-label"> --> <!-- <\!-- <i class="fa fa-globe"></i> -\-> --> <!-- <span></span> --> <!-- </label> --> <!-- <select id="lang-select"> --> <!-- <option value="en">Eng</option> --> <!-- <option value="zh">中文</option> --> <!-- </select> --> <!-- </div> --> <!-- <a id="mobile-nav-toggle"> <span class="mobile-nav-toggle-bar"></span> <span class="mobile-nav-toggle-bar"></span> <span class="mobile-nav-toggle-bar"></span> </a> --> </div> </div> </div> <script type="text/javascript"> $('body').css('background', 'white'); </script> <div class="container"> <div class="row"> <div aria-label="main navigation" class="sphinxsidebar leftsidebar" role="navigation"> <div class="sphinxsidebarwrapper"> <ul> <li class="toctree-l1"><a class="reference internal" href="../api/python/index.html">Python Documents</a></li> <li class="toctree-l1"><a class="reference internal" href="../api/r/index.html">R Documents</a></li> <li class="toctree-l1"><a class="reference internal" href="../api/julia/index.html">Julia Documents</a></li> <li class="toctree-l1"><a class="reference internal" href="../api/c++/index.html">C++ Documents</a></li> <li class="toctree-l1"><a class="reference internal" href="../api/scala/index.html">Scala Documents</a></li> <li class="toctree-l1"><a class="reference internal" href="../api/perl/index.html">Perl Documents</a></li> <li class="toctree-l1"><a class="reference internal" href="../how_to/index.html">HowTo Documents</a></li> <li class="toctree-l1"><a class="reference internal" href="../architecture/index.html">System Documents</a></li> <li class="toctree-l1"><a class="reference internal" href="../tutorials/index.html">Tutorials</a></li> </ul> </div> </div> <div class="content"> <div class="page-tracker"></div> <div class="section" id="build-mxnet-from-source"> <span id="build-mxnet-from-source"></span><h1>Build MXNet from Source<a class="headerlink" href="#build-mxnet-from-source" title="Permalink to this headline">¶</a></h1> <p><strong>NOTE:</strong> For MXNet with Python installation, please refer to the <a class="reference external" href="/versions/0.11.0/get_started/install.html">new install guide</a>.</p> <p>This document explains how to build MXNet from sources. Building MXNet from sources is a 2 step process.</p> <ol class="simple"> <li>Build the MXNet shared library, <code class="docutils literal"><span class="pre">libmxnet.so</span></code>, from <a class="reference external" href="#build-the-shared-library">C++ source files</a></li> <li>Install the language binding for MXNet. MXNet supports - <a class="reference external" href="#build-the-c-package">C++</a>, <a class="reference external" href="#build-the-scala-package">Scala</a>, <a class="reference external" href="#build-the-r-package">R</a>, and <a class="reference external" href="#build-the-julia-package">Julia</a>.</li> </ol> <div class="section" id="build-the-shared-library"> <span id="build-the-shared-library"></span><h2>Build the shared library<a class="headerlink" href="#build-the-shared-library" title="Permalink to this headline">¶</a></h2> <div class="section" id="prerequisites"> <span id="prerequisites"></span><h3>Prerequisites<a class="headerlink" href="#prerequisites" title="Permalink to this headline">¶</a></h3> <p>You need C++ build tools and BLAS library to build MXNet shared library. If you want to run MXNet on GPUs, you need to install CUDA and CuDNN.</p> <div class="section" id="c-build-tools"> <span id="c-build-tools"></span><h4>C++ build tools<a class="headerlink" href="#c-build-tools" title="Permalink to this headline">¶</a></h4> <ol class="simple"> <li>A C++ compiler that supports C++ 11. <a class="reference external" href="https://gcc.gnu.org/gcc-4.8/">G++ (4.8 or later)</a> or <a class="reference external" href="http://clang.llvm.org/">Clang</a> is required.</li> <li><a class="reference external" href="https://git-scm.com/downloads">Git</a> for downloading the sources from Github repository.</li> <li><a class="reference external" href="https://www.gnu.org/software/make/">GNU Make</a> (<a class="reference external" href="https://cmake.org/">cmake</a> for Windows) to build the library.</li> </ol> <p>Select your preferences and follow the instructions to install MXNet from sources.</p> <div class="btn-group opt-group" role="group"> <button class="btn btn-default opt active" type="button">Linux</button> <button class="btn btn-default opt" type="button">macOS</button> <button class="btn btn-default opt" type="button">Windows</button> </div> <script src="../../_static/js/options.js" type="text/javascript"></script><div class="linux"><p>Then select the Linux distribution:</p> <div class="btn-group opt-group" role="group"> <button class="btn btn-default opt active" type="button">Ubuntu</button> <button class="btn btn-default opt" type="button">CentOS</button> <button class="btn btn-default opt" type="button">Others</button> </div><ul class="simple"> <li><strong>Ubuntu</strong> for systems supporting the <code class="docutils literal"><span class="pre">apt-get</span></code> package management program</li> <li><strong>CentOS</strong> for systems supporting the <code class="docutils literal"><span class="pre">yum</span></code> package management program</li> <li><strong>Others</strong> for general Linux-like systems building dependencies from scratch.</li> </ul> <div class="ubuntu"><p>Install build tools and git on <code class="docutils literal"><span class="pre">Ubuntu</span> <span class="pre">>=</span> <span class="pre">13.10</span></code> and <code class="docutils literal"><span class="pre">Debian</span> <span class="pre">>=</span> <span class="pre">8</span></code>.</p> <div class="highlight-bash"><div class="highlight"><pre><span></span>sudo apt-get update <span class="o">&amp;&amp;</span> sudo apt-get install build-essential git </pre></div> </div> </div><div class="centos"><p>Install build tools and git on <code class="docutils literal"><span class="pre">CentOS</span> <span class="pre">>=</span> <span class="pre">7</span></code> and <code class="docutils literal"><span class="pre">Fedora</span> <span class="pre">>=</span> <span class="pre">19</span></code>.</p> <div class="highlight-bash"><div class="highlight"><pre><span></span>sudo yum groupinstall -y <span class="s2">"Development Tools"</span> <span class="o">&amp;&amp;</span> sudo yum install -y git </pre></div> </div> </div><div class="others"><p>Installing both <code class="docutils literal"><span class="pre">git</span></code> and <code class="docutils literal"><span class="pre">make</span></code> by following instructions on the websites is straightforward. Here we provide the instructions to build <code class="docutils literal"><span class="pre">gcc-4.8</span></code> from source codes.</p> <ol class="simple"> <li>Install the 32-bit <code class="docutils literal"><span class="pre">libc</span></code> with one of the following system-specific commands:</li> </ol> <div class="highlight-bash"><div class="highlight"><pre><span></span> sudo apt-get install libc6-dev-i386 <span class="c1"># In Ubuntu</span> sudo yum install glibc-devel.i686 <span class="c1"># In RHEL (Red Hat Linux)</span> sudo yum install glibc-devel.i386 <span class="c1"># In CentOS 5.8</span> sudo yum install glibc-devel.i686 <span class="c1"># In CentOS 6/7</span> </pre></div> </div> <ol class="simple"> <li>Download and extract the <code class="docutils literal"><span class="pre">gcc</span></code> source code with the prerequisites:</li> </ol> <div class="highlight-bash"><div class="highlight"><pre><span></span> wget http://mirrors.concertpass.com/gcc/releases/gcc-4.8.5/gcc-4.8.5.tar.gz tar -zxf gcc-4.8.5.tar.gz <span class="nb">cd</span> gcc-4.8.5 ./contrib/download_prerequisites </pre></div> </div> <ol class="simple"> <li>Build <code class="docutils literal"><span class="pre">gcc</span></code> by using 10 threads and then install to <code class="docutils literal"><span class="pre">/usr/local</span></code></li> </ol> <div class="highlight-bash"><div class="highlight"><pre><span></span> mkdir release <span class="o">&amp;&amp;</span> <span class="nb">cd</span> release ../configure --prefix<span class="o">=</span>/usr/local --enable-languages<span class="o">=</span>c,c++ make -j10 sudo make install </pre></div> </div> <ol class="simple"> <li>Add the lib path to your configure file such as <code class="docutils literal"><span class="pre">~/.bashrc</span></code>:</li> </ol> <div class="highlight-bash"><div class="highlight"><pre><span></span> <span class="nb">export</span> <span class="nv">LD_LIBRARY_PATH</span><span class="o">=</span><span class="si">${</span><span class="nv">LD_LIBRARY_PATH</span><span class="si">}</span>:/usr/local/lib64 </pre></div> </div> </div> </div> <!-- linux --><div class="windows"><ol class="simple"> <li>If <a class="reference external" href="https://www.visualstudio.com/downloads/">Microsoft Visual Studio 2015</a> is not already installed, download and install it. You can download and install the free community edition.</li> <li>Download and Install <a class="reference external" href="https://cmake.org/">CMake</a> if it is not already installed.</li> </ol> </div><div class="macos"><p>Install <a class="reference external" href="https://developer.apple.com/xcode/">Xcode</a>.</p> </div></div> <div class="section" id="blas-library"> <span id="blas-library"></span><h4>BLAS library<a class="headerlink" href="#blas-library" title="Permalink to this headline">¶</a></h4> <p>MXNet relies on the <a class="reference external" href="https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms">BLAS</a> (Basic Linear Algebra Subprograms) library for numerical computations. You can install any one among <a class="reference external" href="http://math-atlas.sourceforge.net/">ATLAS</a>, <a class="reference external" href="http://www.openblas.net/">OpenBLAS</a> and <a class="reference external" href="https://software.intel.com/en-us/intel-mkl">MKL</a>.</p> <div class="linux"> <div class="ubuntu"> ```bash sudo apt-get install libatlas-base-dev ``` </div><div class="centos"> ```bash sudo yum install atlas-devel ``` </div><div class="linux"><p>You can follow this link to build <a class="reference external" href="https://github.com/xianyi/OpenBLAS#installation-from-source">OpenBlas from source</a>.</p> </div> </div><div class="macos"><p>macOS users can skip this step as <code class="docutils literal"><span class="pre">xcode</span></code> ships with a BLAS library.</p> </div><div class="windows"><ol class="simple"> <li>Download pre-built binaries for <a class="reference external" href="https://sourceforge.net/projects/openblas/files/">OpenBLAS</a></li> <li>Set the environment variable <code class="docutils literal"><span class="pre">OpenBLAS_HOME</span></code> to point to the OpenBLAS directory that contains the <code class="docutils literal"><span class="pre">include/</span></code> and <code class="docutils literal"><span class="pre">lib/</span></code> directories. Typically, you can find the directory in <code class="docutils literal"><span class="pre">C:\Program</span> <span class="pre">files</span> <span class="pre">(x86)\OpenBLAS\</span></code>.</li> </ol> </div></div> <div class="section" id="optional-opencv-for-image-loading-and-augmentation"> <span id="optional-opencv-for-image-loading-and-augmentation"></span><h4>Optional: <a class="reference external" href="http://opencv.org/">OpenCV</a> for Image Loading and Augmentation<a class="headerlink" href="#optional-opencv-for-image-loading-and-augmentation" title="Permalink to this headline">¶</a></h4> <div class="linux"> <div class="ubuntu"> ```bash sudo apt-get install libopencv-dev ``` </div><div class="centos"> ```bash sudo apt-get install opencv-devel ``` </div><div class="others"><p>To build OpenCV from source code, you need the <a class="reference external" href="https://cmake.org">cmake</a> library.</p> <ol class="simple"> <li>If you don’t have cmake or if your version of cmake is earlier than 3.6.1, run the following commands to install a newer version of cmake:</li> </ol> <div class="highlight-bash"><div class="highlight"><pre><span></span> wget https://cmake.org/files/v3.6/cmake-3.6.1-Linux-x86_64.tar.gz tar -zxvf cmake-3.6.1-Linux-x86_64.tar.gz <span class="nb">alias</span> <span class="nv">cmake</span><span class="o">=</span><span class="s2">"cmake-3.6.1-Linux-x86_64/bin/cmake"</span> </pre></div> </div> <ol class="simple"> <li>To download and extract the OpenCV source code, run the following commands:</li> </ol> <div class="highlight-bash"><div class="highlight"><pre><span></span> wget https://codeload.github.com/opencv/opencv/zip/2.4.13 unzip <span class="m">2</span>.4.13 <span class="nb">cd</span> opencv-2.4.13 mkdir release <span class="nb">cd</span> release/ </pre></div> </div> <ol class="simple"> <li>Build OpenCV. The following commands build OpenCV with 10 threads. We disabled GPU support, which might significantly slow down an MXNet program running on a GPU processor. It also disables 1394 which might generate a warning. Then install it on <code class="docutils literal"><span class="pre">/usr/local</span></code>.</li> </ol> <div class="highlight-bash"><div class="highlight"><pre><span></span> cmake -D <span class="nv">BUILD_opencv_gpu</span><span class="o">=</span>OFF -D <span class="nv">WITH_CUDA</span><span class="o">=</span>OFF -D <span class="nv">WITH_1394</span><span class="o">=</span>OFF -D <span class="nv">CMAKE_BUILD_TYPE</span><span class="o">=</span>RELEASE -D <span class="nv">CMAKE_INSTALL_PREFIX</span><span class="o">=</span>/usr/local .. make -j10 sudo make install </pre></div> </div> <ol class="simple"> <li>Add the lib path to your configuration such as <code class="docutils literal"><span class="pre">~/.bashrc</span></code>.</li> </ol> <div class="highlight-bash"><div class="highlight"><pre><span></span> <span class="nb">export</span> <span class="nv">PKG_CONFIG_PATH</span><span class="o">=</span><span class="nv">$PKG_CONFIG_PATH</span>:/usr/local/lib/pkgconfig/ </pre></div> </div> </div> </div><div class="windows"><p>First download and install <a class="reference external" href="http://opencv.org/releases.html">OpenCV</a>, then set the environment variable <code class="docutils literal"><span class="pre">OpenCV_DIR</span></code> to point to the OpenCV build directory.</p> </div></div> <div class="section" id="optional-cuda-cudnn-for-nvidia-gpus"> <span id="optional-cuda-cudnn-for-nvidia-gpus"></span><h4>Optional: <a class="reference external" href="https://developer.nvidia.com/cuda-downloads">CUDA</a>/<a class="reference external" href="https://developer.nvidia.com/cudnn">cuDNN</a> for Nvidia GPUs<a class="headerlink" href="#optional-cuda-cudnn-for-nvidia-gpus" title="Permalink to this headline">¶</a></h4> <p>MXNet is compatible with both CUDA 7.5 and 8.0. It is recommended to use cuDNN 5.</p> <div class="linux"> <div class="ubuntu"><p>Install CUDA 7.5 and cuDNN 5 on Ubuntu 14.04</p> <div class="highlight-bash"><div class="highlight"><pre><span></span>wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1404/x86_64/cuda-repo-ubuntu1404_7.5-18_amd64.deb sudo dpkg -i cuda-repo-ubuntu1404_7.5-18_amd64.deb <span class="nb">echo</span> <span class="s2">"deb http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1404/x86_64 /"</span> <span class="p">|</span> sudo tee /etc/apt/sources.list.d/nvidia-ml.list sudo apt-get update sudo apt-get install -y linux-image-extra-<span class="sb">`</span>uname -r<span class="sb">`</span> linux-headers-<span class="sb">`</span>uname -r<span class="sb">`</span> linux-image-<span class="sb">`</span>uname -r<span class="sb">`</span> sudo apt-get install -y cuda libcudnn5-dev<span class="o">=</span><span class="m">5</span>.0.5-1+cuda7.5 </pre></div> </div> </div> </div></div> </div> <div class="section" id="build"> <span id="build"></span><h3>Build<a class="headerlink" href="#build" title="Permalink to this headline">¶</a></h3> <div class="linux macos"><p>First clone the recent codes</p> <div class="highlight-bash"><div class="highlight"><pre><span></span>git clone --recursive https://github.com/dmlc/mxnet <span class="nb">cd</span> mxnet </pre></div> </div> <p>File <a class="reference external" href="https://github.com/dmlc/mxnet/blob/master/make/config.mk"><code class="docutils literal"><span class="pre">make/config.mk</span></code></a> contains all the compilation options. You can edit it and then <code class="docutils literal"><span class="pre">make</span></code>. There are some example build options</p> <p>If you want to build MXNet with C++ language binding, please make sure you read <a class="reference external" href="#build-the-c-package">Build the C++ package</a> first.</p> </div><div class="linux"><ul class="simple"> <li>Build without using OpenCV. <code class="docutils literal"><span class="pre">-j</span></code> runs multiple jobs against multi-core CPUs.</li> </ul> <div class="highlight-bash"><div class="highlight"><pre><span></span> make -j <span class="nv">USE_OPENCV</span><span class="o">=</span><span class="m">0</span> </pre></div> </div> <ul class="simple"> <li>Build with both GPU and OpenCV support</li> </ul> <div class="highlight-bash"><div class="highlight"><pre><span></span> make -j <span class="nv">USE_BLAS</span><span class="o">=</span>openblas <span class="nv">USE_CUDA</span><span class="o">=</span><span class="m">1</span> <span class="nv">USE_CUDA_PATH</span><span class="o">=</span>/usr/local/cuda <span class="nv">USE_CUDNN</span><span class="o">=</span><span class="m">1</span> </pre></div> </div> </div><div class="macos"><ul class="simple"> <li>Build with the default BLAS library and clang installed with <code class="docutils literal"><span class="pre">xcode</span></code> (OPENMP is disabled because it is not supported in default by clang).</li> </ul> <div class="highlight-bash"><div class="highlight"><pre><span></span> make -j <span class="nv">USE_BLAS</span><span class="o">=</span>apple <span class="nv">USE_OPENCV</span><span class="o">=</span><span class="m">0</span> <span class="nv">USE_OPENMP</span><span class="o">=</span><span class="m">0</span> </pre></div> </div> </div><div class="windows"><p>Use <a class="reference external" href="https://cmake.org/">CMake</a> to create a Visual Studio solution in <code class="docutils literal"><span class="pre">./build</span></code>.</p> <p>In Visual Studio, open the solution file,<code class="docutils literal"><span class="pre">.sln</span></code>, and compile it. These commands produce a library called <code class="docutils literal"><span class="pre">mxnet.dll</span></code> in the <code class="docutils literal"><span class="pre">./build/Release/</span></code> or <code class="docutils literal"><span class="pre">./build/Debug</span></code> folder.</p> </div></div> </div> <div class="section" id="build-the-c-package"> <span id="build-the-c-package"></span><h2>Build the C++ package<a class="headerlink" href="#build-the-c-package" title="Permalink to this headline">¶</a></h2> <p>The C++ package has the same prerequisites as the MXNet library, you should also have <code class="docutils literal"><span class="pre">python</span></code> installed. (Both <code class="docutils literal"><span class="pre">python</span></code> 2 and 3 are supported)</p> <p>To enable C++ package, just add <code class="docutils literal"><span class="pre">USE_CPP_PACKAGE=1</span></code> in the build options when building the MXNet shared library.</p> </div> <div class="section" id="build-the-r-package"> <span id="build-the-r-package"></span><h2>Build the R package<a class="headerlink" href="#build-the-r-package" title="Permalink to this headline">¶</a></h2> <p>The R package requires <code class="docutils literal"><span class="pre">R</span></code> to be installed.</p> <div class="ubuntu"><p>Follow the below instructions to install the latest R on Ubuntu 14.04 (trusty) and also the libraries used to build other R package dependencies.</p> <div class="highlight-bash"><div class="highlight"><pre><span></span><span class="nb">echo</span> <span class="s2">"deb http://cran.rstudio.com/bin/linux/ubuntu trusty/"</span> >> /etc/apt/sources.list gpg --keyserver keyserver.ubuntu.com --recv-key E084DAB9 gpg -a --export E084DAB9 <span class="p">|</span> apt-key add - apt-get update apt-get install -y r-base r-base-dev libxml2-dev libxt-dev libssl-dev </pre></div> </div> </div><p>Install the required R package dependencies:</p> <div class="highlight-bash"><div class="highlight"><pre><span></span><span class="nb">cd</span> R-package Rscript -e <span class="s2">"install.packages('devtools', repo = 'https://cran.rstudio.com')"</span> Rscript -e <span class="s2">"library(devtools); library(methods); options(repos=c(CRAN='https://cran.rstudio.com')); install_deps(dependencies = TRUE)"</span> </pre></div> </div> <p>Next, build and install the MXNet R package:</p> <div class="highlight-bash"><div class="highlight"><pre><span></span><span class="nb">cd</span> .. make rpkg R CMD INSTALL mxnet_current_r.tar.gz </pre></div> </div> </div> <div class="section" id="build-the-scala-package"> <span id="build-the-scala-package"></span><h2>Build the Scala package<a class="headerlink" href="#build-the-scala-package" title="Permalink to this headline">¶</a></h2> <p>Both JDK and Maven are required to build the Scala package.</p> <div class="ubuntu"> ```bash sudo apt-get install -y maven default-jdk ``` </div><p>The following command builds the <code class="docutils literal"><span class="pre">.jar</span></code> package:</p> <div class="highlight-bash"><div class="highlight"><pre><span></span>make scalapkg </pre></div> </div> <p>which can be found by <code class="docutils literal"><span class="pre">ls</span> <span class="pre">scala-package/assembly/*/target/*SNAPSHOT.jar</span></code>.</p> <p>Optionally, we can install Scala for the interactive interface.</p> <div class="ubuntu"> ```bash wget http://downloads.lightbend.com/scala/2.11.8/scala-2.11.8.deb dpkg -i scala-2.11.8.deb rm scala-2.11.8.deb ``` </div><p>Then we can start <code class="docutils literal"><span class="pre">scala</span></code> with <code class="docutils literal"><span class="pre">mxnet</span></code> imported by</p> <div class="highlight-bash"><div class="highlight"><pre><span></span>scala -cp scala-package/assembly/*/target/*SNAPSHOT.jar </pre></div> </div> </div> <div class="section" id="build-the-julia-package"> <span id="build-the-julia-package"></span><h2>Build the Julia package<a class="headerlink" href="#build-the-julia-package" title="Permalink to this headline">¶</a></h2> <p>We need to first install Julia.</p> <div class="ubuntu centos linux"><p>The following commands install Julia 0.5.1</p> <div class="highlight-bash"><div class="highlight"><pre><span></span>wget -q https://julialang.s3.amazonaws.com/bin/linux/x64/0.5/julia-0.5.1-linux-x86_64.tar.gz tar -zxf julia-0.5.1-linux-x86_64.tar.gz rm julia-0.5.1-linux-x86_64.tar.gz ln -s <span class="k">$(</span><span class="nb">pwd</span><span class="k">)</span>/julia-6445c82d00/bin/julia /usr/bin/julia </pre></div> </div> </div><p>Next set the environment variable <code class="docutils literal"><span class="pre">MXNET_HOME=/path/to/mxnet</span></code> so that Julia can find the pre-built library.</p> <p>Install the Julia package for MXNet with:</p> <div class="highlight-bash"><div class="highlight"><pre><span></span>julia -e <span class="s1">'Pkg.add("MXNet")'</span> </pre></div> </div> <div class="section" id="build-the-perl-package"> <span id="build-the-perl-package"></span><h3>Build the Perl package<a class="headerlink" href="#build-the-perl-package" title="Permalink to this headline">¶</a></h3> <p>Run the following command from the MXNet source root directory to build the MXNet Perl package:</p> <div class="highlight-bash"><div class="highlight"><pre><span></span> sudo apt-get install libmouse-perl pdl cpanminus swig libgraphviz-perl cpanm -q -L <span class="s2">"</span><span class="si">${</span><span class="nv">HOME</span><span class="si">}</span><span class="s2">/perl5"</span> Function::Parameters <span class="nv">MXNET_HOME</span><span class="o">=</span><span class="si">${</span><span class="nv">PWD</span><span class="si">}</span> <span class="nb">export</span> <span class="nv">LD_LIBRARY_PATH</span><span class="o">=</span><span class="si">${</span><span class="nv">MXNET_HOME</span><span class="si">}</span>/lib <span class="nb">export</span> <span class="nv">PERL5LIB</span><span class="o">=</span><span class="si">${</span><span class="nv">HOME</span><span class="si">}</span>/perl5/lib/perl5 <span class="nb">cd</span> <span class="si">${</span><span class="nv">MXNET_HOME</span><span class="si">}</span>/perl-package/AI-MXNetCAPI/ perl Makefile.PL <span class="nv">INSTALL_BASE</span><span class="o">=</span><span class="si">${</span><span class="nv">HOME</span><span class="si">}</span>/perl5 make install <span class="nb">cd</span> <span class="si">${</span><span class="nv">MXNET_HOME</span><span class="si">}</span>/perl-package/AI-NNVMCAPI/ perl Makefile.PL <span class="nv">INSTALL_BASE</span><span class="o">=</span><span class="si">${</span><span class="nv">HOME</span><span class="si">}</span>/perl5 make install <span class="nb">cd</span> <span class="si">${</span><span class="nv">MXNET_HOME</span><span class="si">}</span>/perl-package/AI-MXNet/ perl Makefile.PL <span class="nv">INSTALL_BASE</span><span class="o">=</span><span class="si">${</span><span class="nv">HOME</span><span class="si">}</span>/perl5 make install </pre></div> </div> </div> </div> </div> </div> </div> <div aria-label="main navigation" class="sphinxsidebar rightsidebar" role="navigation"> <div class="sphinxsidebarwrapper"> <h3><a href="../index.html">Table Of Contents</a></h3> <ul> <li><a class="reference internal" href="#">Build MXNet from Source</a><ul> <li><a class="reference internal" href="#build-the-shared-library">Build the shared library</a><ul> <li><a class="reference internal" href="#prerequisites">Prerequisites</a><ul> <li><a class="reference internal" href="#c-build-tools">C++ build tools</a></li> <li><a class="reference internal" href="#blas-library">BLAS library</a></li> <li><a class="reference internal" href="#optional-opencv-for-image-loading-and-augmentation">Optional: OpenCV for Image Loading and Augmentation</a></li> <li><a class="reference internal" href="#optional-cuda-cudnn-for-nvidia-gpus">Optional: CUDA/cuDNN for Nvidia GPUs</a></li> </ul> </li> <li><a class="reference internal" href="#build">Build</a></li> </ul> </li> <li><a class="reference internal" href="#build-the-c-package">Build the C++ package</a></li> <li><a class="reference internal" href="#build-the-r-package">Build the R package</a></li> <li><a class="reference internal" href="#build-the-scala-package">Build the Scala package</a></li> <li><a class="reference internal" href="#build-the-julia-package">Build the Julia package</a><ul> <li><a class="reference internal" href="#build-the-perl-package">Build the Perl package</a></li> </ul> </li> </ul> </li> </ul> </div> </div> </div><div class="footer"> <div class="section-disclaimer"> <div class="container"> <div> <img height="60" src="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/image/apache_incubator_logo.png"/> <p> Apache MXNet is an effort undergoing incubation at The Apache Software Foundation (ASF), <strong>sponsored by the <i>Apache Incubator</i></strong>. Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, and decision making process have stabilized in a manner consistent with other successful ASF projects. While incubation status is not necessarily a reflection of the completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF. </p> <p> "Copyright © 2017-2018, The Apache Software Foundation Apache MXNet, MXNet, Apache, the Apache feather, and the Apache MXNet project logo are either registered trademarks or trademarks of the Apache Software Foundation." </p> </div> </div> </div> </div> <!-- pagename != index --> </div> <script crossorigin="anonymous" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> <script src="../_static/js/sidebar.js" type="text/javascript"></script> <script src="../_static/js/search.js" type="text/javascript"></script> <script src="../_static/js/navbar.js" type="text/javascript"></script> <script src="../_static/js/clipboard.min.js" type="text/javascript"></script> <script src="../_static/js/copycode.js" type="text/javascript"></script> <script src="../_static/js/page.js" type="text/javascript"></script> <script src="../_static/js/docversion.js" type="text/javascript"></script> <script type="text/javascript"> $('body').ready(function () { $('body').css('visibility', 'visible'); }); </script> </body> </html>