blob: e4d031a283ea883134ee1b68400b0b39e8328be0 [file] [log] [blame]
<!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="Run MXNet Scala Examples Using the IntelliJ IDE" 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="Run MXNet Scala Examples Using the IntelliJ IDE" property="og:description"/>
<title>Run MXNet Scala Examples Using the IntelliJ IDE — 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/1.2.1/searchindex.js"); Search.init();}); </script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new
Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-96378503-1', 'auto');
ga('send', 'pageview');
</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/1.2.1/install/index.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/1.2.1/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/1.2.1/api/python/index.html">Python</a></li>
<li><a class="main-nav-link" href="/versions/1.2.1/api/c++/index.html">C++</a></li>
<li><a class="main-nav-link" href="/versions/1.2.1/api/julia/index.html">Julia</a></li>
<li><a class="main-nav-link" href="/versions/1.2.1/api/perl/index.html">Perl</a></li>
<li><a class="main-nav-link" href="/versions/1.2.1/api/r/index.html">R</a></li>
<li><a class="main-nav-link" href="/versions/1.2.1/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/1.2.1/faq/index.html">FAQ</a></li>
<li><a class="main-nav-link" href="/versions/1.2.1/tutorials/index.html">Tutorials</a>
<li><a class="main-nav-link" href="https://github.com/apache/incubator-mxnet/tree/1.2.1/example">Examples</a></li>
<li><a class="main-nav-link" href="/versions/1.2.1/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/1.2.1/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/1.2.1">Github</a></li>
<li><a class="main-nav-link" href="/versions/1.2.1/community/contribute.html">Contribute</a></li>
<li><a class="main-nav-link" href="/versions/1.2.1/community/powered_by.html">Powered By</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">1.2.1<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/">1.7</a></li><li><a href=/versions/1.6/>1.6</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/1.2.1/install/index.html">Install</a></li>
<li><a class="main-nav-link" href="/versions/1.2.1/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/1.2.1/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/1.2.1/api/python/index.html">Python</a></li>
<li><a class="main-nav-link" href="/versions/1.2.1/api/c++/index.html">C++</a></li>
<li><a class="main-nav-link" href="/versions/1.2.1/api/julia/index.html">Julia</a></li>
<li><a class="main-nav-link" href="/versions/1.2.1/api/perl/index.html">Perl</a></li>
<li><a class="main-nav-link" href="/versions/1.2.1/api/r/index.html">R</a></li>
<li><a class="main-nav-link" href="/versions/1.2.1/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/1.2.1/faq/index.html" tabindex="-1">FAQ</a></li>
<li><a href="/versions/1.2.1/tutorials/index.html" tabindex="-1">Tutorials</a></li>
<li><a href="https://github.com/apache/incubator-mxnet/tree/1.2.1/example" tabindex="-1">Examples</a></li>
<li><a href="/versions/1.2.1/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/1.2.1/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/1.2.1" tabindex="-1">Github</a></li>
<li><a href="/versions/1.2.1/community/contribute.html" tabindex="-1">Contribute</a></li>
<li><a href="/versions/1.2.1/community/powered_by.html" tabindex="-1">Powered By</a></li>
</ul>
</li>
<li id="dropdown-menu-position-anchor-version-mobile" class="dropdown-submenu" style="position: relative"><a href="#" tabindex="-1">1.2.1</a><ul class="dropdown-menu"><li><a tabindex="-1" href=/>master</a></li><li><a tabindex="-1" href=/versions/1.6/>1.6</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="../../faq/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="../index.html">Tutorials</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../community/index.html">Community</a></li>
</ul>
</div>
</div>
<div class="content">
<div class="page-tracker"></div>
<div class="section" id="run-mxnet-scala-examples-using-the-intellij-ide">
<span id="run-mxnet-scala-examples-using-the-intellij-ide"></span><h1>Run MXNet Scala Examples Using the IntelliJ IDE<a class="headerlink" href="#run-mxnet-scala-examples-using-the-intellij-ide" title="Permalink to this headline"></a></h1>
<p>This tutorial guides you through setting up a Scala project in the IntelliJ IDE and shows how to use an MXNet package from your application.</p>
<div class="section" id="prerequisites">
<span id="prerequisites"></span><h2>Prerequisites:<a class="headerlink" href="#prerequisites" title="Permalink to this headline"></a></h2>
<p>To use this tutorial you need the following items, however after this list, installation info for macOS is provided for your benefit:</p>
<ul class="simple">
<li><a class="reference external" href="http://www.oracle.com/technetwork/java/javase/downloads/index.html">Java 8 JDK</a></li>
<li><a class="reference external" href="https://maven.apache.org/install.html">Maven</a></li>
<li><a class="reference external" href="https://www.scala-lang.org/download/">Scala</a> - comes with IntelliJ, so you don’t need to install it separately</li>
<li><a class="reference external" href="#build-the-mxnet-shared-library-and-scala-package">MXNet Shared Library and Scala Package</a></li>
<li><a class="reference external" href="https://www.jetbrains.com/idea/">IntelliJ IDE</a></li>
</ul>
</div>
<div class="section" id="mac-prerequisites-setup">
<span id="mac-prerequisites-setup"></span><h2>Mac Prerequisites Setup<a class="headerlink" href="#mac-prerequisites-setup" title="Permalink to this headline"></a></h2>
<p>For other operating systems, visit each Prerequisite’s website and follow their installations instructions. For macOS, you’re in luck:</p>
<p><strong>Step 1.</strong> Install brew:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="o">/</span><span class="n">usr</span><span class="o">/</span><span class="nb">bin</span><span class="o">/</span><span class="n">ruby</span> <span class="o">-</span><span class="n">e</span> <span class="s2">"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"</span>
</pre></div>
</div>
<p><strong>Step 2.</strong> Install Java 8 JDK:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">brew</span> <span class="n">tap</span> <span class="n">caskroom</span><span class="o">/</span><span class="n">versions</span>
<span class="n">brew</span> <span class="n">cask</span> <span class="n">install</span> <span class="n">java8</span>
</pre></div>
</div>
<p><strong>Step 3.</strong> Install maven:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">brew</span> <span class="n">update</span>
<span class="n">brew</span> <span class="n">install</span> <span class="n">maven</span>
</pre></div>
</div>
</div>
<div class="section" id="build-the-mxnet-shared-library-and-scala-package">
<span id="build-the-mxnet-shared-library-and-scala-package"></span><h2>Build the MXNet Shared Library and Scala Package<a class="headerlink" href="#build-the-mxnet-shared-library-and-scala-package" title="Permalink to this headline"></a></h2>
<p>This depends on your operating system. Instructions for macOS, Ubuntu, and Windows are provided:</p>
<table border="1" class="docutils">
<colgroup>
<col width="33%"/>
<col width="33%"/>
<col width="33%"/>
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">OS</th>
<th class="head">Step 1</th>
<th class="head">Step 2</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>macOS</td>
<td><a class="reference external" href="/versions/1.2.1/install/osx_setup.html#build-the-shared-library">Shared Library for macOS</a></td>
<td><a class="reference external" href="/versions/1.2.1/install/osx_setup.html#install-the-mxnet-package-for-scala">Scala Package for macOS</a></td>
</tr>
<tr class="row-odd"><td>Ubuntu</td>
<td><a class="reference external" href="/versions/1.2.1/install/ubuntu_setup.html#installing-mxnet-on-ubuntu">Shared Library for Ubuntu</a></td>
<td><a class="reference external" href="/versions/1.2.1/install/ubuntu_setup.html#install-the-mxnet-package-for-scala">Scala Package for Ubuntu</a></td>
</tr>
<tr class="row-even"><td>Windows</td>
<td><a class="reference external" href="/versions/1.2.1/install/windows_setup.html#build-the-shared-library">Shared Library for Windows</a></td>
<td><a class="reference external" href="/versions/1.2.1/install/windows_setup.html#installing-the-mxnet-package-for-scala">Scala Package for Windows</a></td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="build-scala-from-an-existing-mxnet-installation">
<span id="build-scala-from-an-existing-mxnet-installation"></span><h2>Build Scala from an Existing MXNet Installation<a class="headerlink" href="#build-scala-from-an-existing-mxnet-installation" title="Permalink to this headline"></a></h2>
<p>If you have already built MXNet <strong>from source</strong> and are looking to setup Scala from that point, you may simply run the following from the MXNet source root:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">make</span> <span class="n">scalapkg</span>
<span class="n">make</span> <span class="n">scalainstall</span>
</pre></div>
</div>
</div>
<div class="section" id="set-up-your-project">
<span id="set-up-your-project"></span><h2>Set Up Your Project<a class="headerlink" href="#set-up-your-project" title="Permalink to this headline"></a></h2>
<p>Now that you’ve installed your prerequisites, you are ready to setup IntelliJ and your first MXNet-Scala project!</p>
<p><strong>Step 1.</strong> Install and setup IntelliJ:
- When prompted for what to features to enable during IntelliJ’s first startup, make sure you select Scala.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="o">-</span> <span class="n">Install</span> <span class="n">the</span> <span class="n">plugin</span> <span class="k">for</span> <span class="n">IntelliJ</span> <span class="n">IDE</span> <span class="n">by</span> <span class="n">following</span> <span class="n">these</span> <span class="n">steps</span><span class="p">:</span>
</pre></div>
</div>
<p>On <strong>Menu</strong>, choose <strong>Preferences</strong>, choose <strong>Plugins</strong>, type <strong>Scala</strong>, and then choose <strong>Install</strong>. For further plugin help and instructions, refer to <a class="reference external" href="https://www.jetbrains.com/help/idea/scala.html">Scala plugin setup for IDE</a>.</p>
<p><strong>Step 2.</strong> Create a new project:</p>
<p><img alt="intellij welcome" src="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/scala/intellij-welcome.png"/></p>
<p>From the IntelliJ welcome screen, select “Create New Project”.</p>
<p><img alt="maven project type" src="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/scala/intellij-project-type.png"/></p>
<p>Choose the Maven project type.</p>
<p><img alt="maven project type - archetype" src="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/scala/intellij-project-type-archetype-check.png"/></p>
<p>Select the checkbox for <code class="docutils literal"><span class="pre">Create</span> <span class="pre">from</span> <span class="pre">archetype</span></code>.</p>
<p><img alt="maven project type - archetype" src="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/scala/intellij-project-type-archetype-add.png"/></p>
<p>Click the <code class="docutils literal"><span class="pre">Add</span> <span class="pre">Archetype</span></code> button, and add the following information to each field.</p>
<p><strong>GroupId</strong></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">net</span><span class="o">.</span><span class="n">alchim31</span><span class="o">.</span><span class="n">maven</span>
</pre></div>
</div>
<p><strong>ArtifactId</strong></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">scala</span><span class="o">-</span><span class="n">archetype</span><span class="o">-</span><span class="n">simple</span>
</pre></div>
</div>
<p><strong>Version</strong></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="mf">1.6</span>
</pre></div>
</div>
<p><strong>Repository</strong></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">https</span><span class="p">:</span><span class="o">//</span><span class="n">mvnrepository</span><span class="o">.</span><span class="n">com</span><span class="o">/</span><span class="n">artifact</span><span class="o">/</span><span class="n">net</span><span class="o">.</span><span class="n">alchim31</span><span class="o">.</span><span class="n">maven</span><span class="o">/</span><span class="n">scala</span><span class="o">-</span><span class="n">archetype</span><span class="o">-</span><span class="n">simple</span>
</pre></div>
</div>
<p><img alt="maven project type - archetype" src="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/scala/intellij-project-type-archetype-add-confirm.png"/></p>
<p>Click <code class="docutils literal"><span class="pre">Ok</span></code> to add the archetype, make sure it is selected from the list, and then click <code class="docutils literal"><span class="pre">Next</span></code>.</p>
<p><img alt="project metadata" src="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/scala/intellij-project-metadata.png"/></p>
<p>Set the project’s metadata. For this tutorial, use the following:</p>
<p><strong>GroupId</strong></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">your</span><span class="o">-</span><span class="n">name</span>
</pre></div>
</div>
<p><strong>ArtifactId</strong></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">ArtifactId</span><span class="p">:</span> <span class="n">scalaMXNet</span>
</pre></div>
</div>
<p><strong>Version</strong></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="mf">1.0</span><span class="o">-</span><span class="n">SNAPSHOT</span>
</pre></div>
</div>
<p><img alt="project properties" src="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/scala/intellij-project-properties.png"/></p>
<p>Review the project’s properties. The settings can be left as their default.</p>
<p><img alt="project location" src="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/scala/intellij-project-location.png"/></p>
<p>Set the project’s location. The rest of the settings can be left as their default.</p>
<p><img alt="project 1" src="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/scala/intellij-project-1.png"/></p>
<p>After clicking Finish, you will be presented with the project’s first view.
The project’s <code class="docutils literal"><span class="pre">pom.xml</span></code> will be open for editing.</p>
<p><strong>Step 3.</strong> Setup project properties:</p>
<ul class="simple">
<li>Specify project properties in <code class="docutils literal"><span class="pre">pom.xml</span></code> by pasting the following content in the <code class="docutils literal"><span class="pre"><properties></span></code> tag. You will be overwriting the <code class="docutils literal"><span class="pre"><scala.version></span></code> tag in the process, upgrading from <code class="docutils literal"><span class="pre">2.11.5</span></code> to <code class="docutils literal"><span class="pre">2.11.8</span></code>.</li>
</ul>
<div class="highlight-xml"><div class="highlight"><pre><span></span><span class="nt"><properties></span>
<span class="nt"><scala.version></span>2.11.8<span class="nt"></scala.version></span>
<span class="nt"><scala.binary.version></span>2.11<span class="nt"></scala.binary.version></span>
<span class="nt"></properties></span>
</pre></div>
</div>
<p><strong>Step 4.</strong> Setup project profiles and platforms:</p>
<ul class="simple">
<li>Specify project profiles and platforms in <code class="docutils literal"><span class="pre">pom.xml</span></code> by pasting the following content below the <code class="docutils literal"><span class="pre"></properties></span></code> tag:</li>
</ul>
<div class="highlight-xml"><div class="highlight"><pre><span></span><span class="nt"><profiles></span>
<span class="nt"><profile></span>
<span class="nt"><id></span>osx-x86_64-cpu<span class="nt"></id></span>
<span class="nt"><properties></span>
<span class="nt"><platform></span>osx-x86_64-cpu<span class="nt"></platform></span>
<span class="nt"></properties></span>
<span class="nt"></profile></span>
<span class="nt"><profile></span>
<span class="nt"><id></span>linux-x86_64-cpu<span class="nt"></id></span>
<span class="nt"><properties></span>
<span class="nt"><platform></span>linux-x86_64-cpu<span class="nt"></platform></span>
<span class="nt"></properties></span>
<span class="nt"></profile></span>
<span class="nt"><profile></span>
<span class="nt"><id></span>linux-x86_64-gpu<span class="nt"></id></span>
<span class="nt"><properties></span>
<span class="nt"><platform></span>linux-x86_64-gpu<span class="nt"></platform></span>
<span class="nt"></properties></span>
<span class="nt"></profile></span>
<span class="nt"></profiles></span>
</pre></div>
</div>
<p><strong>Step 5.</strong> Setup project dependencies:</p>
<ul class="simple">
<li>Specify project dependencies in <code class="docutils literal"><span class="pre">pom.xml</span></code> adding the dependencies listed below. Place them inside the <code class="docutils literal"><span class="pre"><dependencies></span></code> tag:</li>
</ul>
<div class="highlight-xml"><div class="highlight"><pre><span></span><span class="nt"><dependencies></span>
<span class="c"><!-- Begin deps for MXNet --></span>
<span class="nt"><dependency></span>
<span class="nt"><groupId></span>ml.dmlc.mxnet<span class="nt"></groupId></span>
<span class="nt"><artifactId></span>mxnet-full_${scala.binary.version}-${platform}<span class="nt"></artifactId></span>
<span class="nt"><version></span>1.2.0<span class="nt"></version></span>
<span class="nt"><scope></span>system<span class="nt"></scope></span>
<span class="nt"><systemPath></span>/Development/incubator-mxnet/scala-package/assembly/osx-x86_64-cpu/target/mxnet-full_2.11-osx-x86_64-cpu-1.2.0-SNAPSHOT.jar<span class="nt"></systemPath></span>
<span class="nt"></dependency></span>
<span class="nt"><dependency></span>
<span class="nt"><groupId></span>args4j<span class="nt"></groupId></span>
<span class="nt"><artifactId></span>args4j<span class="nt"></artifactId></span>
<span class="nt"><version></span>2.0.29<span class="nt"></version></span>
<span class="nt"></dependency></span>
<span class="nt"><dependency></span>
<span class="nt"><groupId></span>org.slf4j<span class="nt"></groupId></span>
<span class="nt"><artifactId></span>slf4j-api<span class="nt"></artifactId></span>
<span class="nt"><version></span>${slf4jVersion}<span class="nt"></version></span>
<span class="nt"></dependency></span>
<span class="nt"><dependency></span>
<span class="nt"><groupId></span>org.slf4j<span class="nt"></groupId></span>
<span class="nt"><artifactId></span>slf4j-log4j12<span class="nt"></artifactId></span>
<span class="nt"><version></span>${slf4jVersion}<span class="nt"></version></span>
<span class="nt"></dependency></span>
<span class="c"><!-- End deps for MXNet --></span>
<span class="nt"><dependency></span>
<span class="nt"><groupId></span>org.scala-lang<span class="nt"></groupId></span>
<span class="nt"><artifactId></span>scala-library<span class="nt"></artifactId></span>
<span class="nt"><version></span>${scala.version}<span class="nt"></version></span>
<span class="nt"></dependency></span>
<span class="c"><!-- Test --></span>
<span class="nt"><dependency></span>
<span class="nt"><groupId></span>junit<span class="nt"></groupId></span>
<span class="nt"><artifactId></span>junit<span class="nt"></artifactId></span>
<span class="nt"><version></span>4.11<span class="nt"></version></span>
<span class="nt"><scope></span>test<span class="nt"></scope></span>
<span class="nt"></dependency></span>
<span class="nt"><dependency></span>
<span class="nt"><groupId></span>org.specs2<span class="nt"></groupId></span>
<span class="nt"><artifactId></span>specs2-core_${scala.compat.version}<span class="nt"></artifactId></span>
<span class="nt"><version></span>2.4.16<span class="nt"></version></span>
<span class="nt"><scope></span>test<span class="nt"></scope></span>
<span class="nt"></dependency></span>
<span class="nt"><dependency></span>
<span class="nt"><groupId></span>org.specs2<span class="nt"></groupId></span>
<span class="nt"><artifactId></span>specs2-junit_${scala.compat.version}<span class="nt"></artifactId></span>
<span class="nt"><version></span>2.4.16<span class="nt"></version></span>
<span class="nt"><scope></span>test<span class="nt"></scope></span>
<span class="nt"></dependency></span>
<span class="nt"><dependency></span>
<span class="nt"><groupId></span>org.scalatest<span class="nt"></groupId></span>
<span class="nt"><artifactId></span>scalatest_${scala.compat.version}<span class="nt"></artifactId></span>
<span class="nt"><version></span>2.2.4<span class="nt"></version></span>
<span class="nt"><scope></span>test<span class="nt"></scope></span>
<span class="nt"></dependency></span>
<span class="nt"></dependencies></span>
</pre></div>
</div>
<p><img alt="project 2" src="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/scala/intellij-project-2.png"/></p>
<p>Note the <code class="docutils literal"><span class="pre"><systemPath></span></code> tag and update it to match the file path to the jar file that was created when you built the MXNet-Scala package. It can be found in the <code class="docutils literal"><span class="pre">mxnet-incubator/scala-package/assembly/{platform}/target</span></code> directory, and is named with the pattern <code class="docutils literal"><span class="pre">mxnet-full_${scala.binary.version}-${platform}-{version-SNAPSHOT}.jar</span></code>.</p>
<p><strong>Step 6.</strong> Import dependencies with Maven:</p>
<ul class="simple">
<li>Note the prompt in the lower right corner that states “Maven projects need to be imported”.</li>
</ul>
<p><img alt="project 3" src="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/scala/intellij-project-3.png"/></p>
<p>Click “Import Changes” in this prompt.</p>
<p><strong>Step 7.</strong> Build the project:</p>
<ul class="simple">
<li>To build the project, from the menu choose Build, and then choose Build Project.</li>
</ul>
<p><strong>Note</strong>: During the build you may experience <code class="docutils literal"><span class="pre">[ERROR]</span> <span class="pre">scalac</span> <span class="pre">error:</span> <span class="pre">bad</span> <span class="pre">option:</span> <span class="pre">'-make:transitive'</span></code>. You can fix this by deleting or commenting this out in your <code class="docutils literal"><span class="pre">pom.xml</span></code>. This line in question is: <code class="docutils literal"><span class="pre"><arg>-make:transitive</arg></span></code>.</p>
<p><strong>Step 8.</strong> Run the Hello World App:</p>
<p><img alt="hello world app" src="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/scala/intellij-project-hello-world-app.png"/></p>
<p>Navigate to the App included with the project.</p>
<p><img alt="run hello world" src="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/scala/intellij-project-hello-world-run.png"/></p>
<p>Run the App by clicking the green arrow, and verify the Hello World output</p>
<p><strong>Step 9.</strong> Run Sample MXNet Code in the App:</p>
<p><img alt="run hello mxnet" src="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/scala/intellij-project-hello-mxnet.png"/></p>
<p>Paste the following code in the App, overwriting the original hello world code. Then click the green arrow to run it.</p>
<div class="highlight-scala"><div class="highlight"><pre><span></span><span class="k">object</span> <span class="nc">App</span> <span class="k">extends</span> <span class="nc">App</span> <span class="o">{</span>
<span class="k">import</span> <span class="nn">ml.dmlc.mxnet._</span>
<span class="k">import</span> <span class="nn">org.apache.log4j.BasicConfigurator</span>
<span class="nc">BasicConfigurator</span><span class="o">.</span><span class="n">configure</span><span class="o">()</span>
<span class="k">private</span> <span class="k">val</span> <span class="n">a</span> <span class="k">=</span> <span class="nc">NDArray</span><span class="o">.</span><span class="n">ones</span><span class="o">(</span><span class="mi">2</span><span class="o">,</span> <span class="mi">3</span><span class="o">)</span>
<span class="n">println</span><span class="o">(</span><span class="s">"Testing MXNet by generating an 2x3 NDArray..."</span><span class="o">)</span>
<span class="n">println</span><span class="o">(</span><span class="s">"Shape is: "</span><span class="o">)</span>
<span class="n">println</span><span class="o">(</span><span class="n">a</span><span class="o">.</span><span class="n">shape</span><span class="o">)</span>
<span class="o">}</span>
</pre></div>
</div>
<p><img alt="run hello world" src="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/scala/intellij-project-hello-mxnet-output.png"/></p>
<p>Your result should be similar to this output.</p>
<div class="section" id="command-line-build-option">
<span id="command-line-build-option"></span><h3>Command Line Build Option<a class="headerlink" href="#command-line-build-option" title="Permalink to this headline"></a></h3>
<ul class="simple">
<li>You can also compile the project by using the following command at the command line. Change directories to this project’s folder then run the following:</li>
</ul>
<div class="highlight-bash"><div class="highlight"><pre><span></span> mvn clean package -e -P osx-x86_64-cpu
</pre></div>
</div>
<p>The <code class="docutils literal"><span class="pre">-P</span> <span class="pre"><platform></span></code> parameter tells the build which platform to target.
The <code class="docutils literal"><span class="pre">-e</span></code> will give you more details if the build fails. If it succeeds, you should see a lot of info and some warning messages, followed by:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span><span class="o">[</span>INFO<span class="o">]</span> ------------------------------------------------------------------------
<span class="o">[</span>INFO<span class="o">]</span> BUILD SUCCESS
<span class="o">[</span>INFO<span class="o">]</span> ------------------------------------------------------------------------
<span class="o">[</span>INFO<span class="o">]</span> Total time: <span class="m">1</span>.186 s
<span class="o">[</span>INFO<span class="o">]</span> Finished at: <span class="m">2018</span>-03-06T15:17:36-08:00
<span class="o">[</span>INFO<span class="o">]</span> Final Memory: 11M/155M
<span class="o">[</span>INFO<span class="o">]</span> ------------------------------------------------------------------------
</pre></div>
</div>
<p>The build generates a new jar file in the <code class="docutils literal"><span class="pre">target</span></code> folder called <code class="docutils literal"><span class="pre">scalaInference-1.0-SNAPSHOT.jar</span></code>.</p>
</div>
</div>
<div class="section" id="next-steps">
<span id="next-steps"></span><h2>Next Steps<a class="headerlink" href="#next-steps" title="Permalink to this headline"></a></h2>
<p>For more information about MXNet Scala resources, see the following:</p>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference external" href="/versions/1.2.1/api/scala/">Scala API</a></li>
<li class="toctree-l1"><a class="reference external" href="https://github.com/incubator-mxnet/tree/1.2.1/scala-package/examples/">More Scala Examples</a></li>
<li class="toctree-l1"><a class="reference external" href="/versions/1.2.1/tutorials/index.html">MXNet tutorials index</a></li>
</ul>
</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="#">Run MXNet Scala Examples Using the IntelliJ IDE</a><ul>
<li><a class="reference internal" href="#prerequisites">Prerequisites:</a></li>
<li><a class="reference internal" href="#mac-prerequisites-setup">Mac Prerequisites Setup</a></li>
<li><a class="reference internal" href="#build-the-mxnet-shared-library-and-scala-package">Build the MXNet Shared Library and Scala Package</a></li>
<li><a class="reference internal" href="#build-scala-from-an-existing-mxnet-installation">Build Scala from an Existing MXNet Installation</a></li>
<li><a class="reference internal" href="#set-up-your-project">Set Up Your Project</a><ul>
<li><a class="reference internal" href="#command-line-build-option">Command Line Build Option</a></li>
</ul>
</li>
<li><a class="reference internal" href="#next-steps">Next Steps</a></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>