The purpose of this HowTo is to share those notes, but if you're interested in learning more about MXNet, the "MXNet Gluon in 60-minutes" article by Thom Lane provides a good introduction. Lane also provides a series of YouTube videos, and at the documentation page, you can find his Jupyter notebooks for the "Gluon Crash Course."
And if you enjoy programming in Perl, then check out the AI::MXNet module by Sergey Kolychev. He kept the Perl syntax as similar as possible to the Python syntax, so I used it to replicate Lane's MXNet course in Perl.
In his own writing, Kolychev also provides an introduction, some examples, a script on neural networks and a picture of his dog. In my work, I am using MXNet to develop a dictionary and a machine translator.
1. set variables and paths
After building the shared library, I wanted to store it in /home/soul/.local/mxnet/lib, so my first step was to add the following variables and paths to my $HOME/.bashrc
Code: Select all
## local library path -- contains libmxnet.so and more
export LD_LIBRARY_PATH="/home/soul/.local/mxnet/lib"
## python path
export PYTHONPATH="/home/soul/.local/lib/python3.7/site-packages"
## perl path
export PERL5LIB="/home/soul/.perl/lib/perl5"
## set PATH so it includes $HOME/.perl/bin if it exists
if [ -d "$HOME/.perl/bin" ] ; then
PATH="$HOME/.perl/bin:$PATH"
fi
## set PATH so it includes $HOME/.local/bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
PATH="$HOME/.local/bin:$PATH"
fi
## set PATH so it includes $HOME/.bin if it exists
if [ -d "$HOME/.bin" ] ; then
PATH="$HOME/.bin:$PATH"
fi
Next, I installed the build dependencies for the shared library:
Code: Select all
apt-get install build-essential ca-certificates cmake git liblapack-dev libmkldnn-dev libopenblas-dev libopencv-dev ninja-build python3-dev unzip wget
Code: Select all
apt-get install python3-pip
Code: Select all
apt-get install libmouse-perl pdl cpanminus swig libgraphviz-perl
Having chosen those paths and variables and having installed the build dependencies, I downloaded the apache-mxnet-src-1.4.1-incubating.tar.gz tarball from https://github.com/apache/incubator-mxn ... /tag/1.4.1 and began to build.
First, I extracted the tarball and entered the directory:
Code: Select all
tar -xzf apache-mxnet-src-1.4.1-incubating.tar.gz
cd apache-mxnet-src-1.4.1-incubating/
MXNET_HOME=${PWD}
Code: Select all
make -j $(nproc) USE_OPENCV=1 USE_BLAS=openblas USE_MKLDNN=1 | tee ../build-log_2019-05-28.txt
Code: Select all
USE_CUDA=1 USE_CUDA_PATH=/usr/local/cuda USE_CUDNN=1
Code: Select all
cp lib/libiomp5.so ${LD_LIBRARY_PATH}/.
cp lib/libmkldnn.so.0 ${LD_LIBRARY_PATH}/.
cp lib/libmklml_intel.so ${LD_LIBRARY_PATH}/.
cp lib/libmxnet.a ${LD_LIBRARY_PATH}/.
cp lib/libmxnet.so ${LD_LIBRARY_PATH}/.
Next, I installed the Python package:
Code: Select all
cd ${MXNET_HOME}/python
pip3 install .
Code: Select all
cd /home/soul/.local/lib/python3.7/site-packages/mxnet
ln -s /home/soul/.local/mxnet/lib/libmxnet.so libmxnet.so
ln -s /home/soul/.local/mxnet/lib/libmklml_intel.so libmklml_intel.so
ln -s /home/soul/.local/mxnet/lib/libiomp5.so libiomp5.so
After that, I validated the installation by passing the following commands to the python3 interpreter:
Code: Select all
>>> import mxnet as mx
>>> a = mx.nd.ones((2, 3))
>>> b = a * 2 + 1
>>> b.asnumpy()
Code: Select all
array([[ 3., 3., 3.],
[ 3., 3., 3.]], dtype=float32)
6. install the Perl bindings
Next, I installed the Perl packages:
Code: Select all
cpanm -q -L "${HOME}/.perl" Function::Parameters Hash::Ordered PDL::CCS
cd ${MXNET_HOME}/perl-package/AI-MXNetCAPI/
perl Makefile.PL INSTALL_BASE="${HOME}/.perl"
make install
cd ${MXNET_HOME}/perl-package/AI-NNVMCAPI/
perl Makefile.PL INSTALL_BASE="${HOME}/.perl"
make install
cd ${MXNET_HOME}/perl-package/AI-MXNet
perl Makefile.PL INSTALL_BASE="${HOME}/.perl"
make test TEST_VERBOSE=1
make install
cd ${MXNET_HOME}/perl-package/AI-MXNet-Gluon-Contrib
perl Makefile.PL INSTALL_BASE="${HOME}/.perl"
make install
cd ${MXNET_HOME}/perl-package/AI-MXNet-Gluon-ModelZoo
perl Makefile.PL INSTALL_BASE="${HOME}/.perl"
make test TEST_VERBOSE=1
make install
Code: Select all
pdl> use AI::MXNet qw(mx)
pdl> $a = mx->nd->ones([2, 3])
pdl> $b = $a * 2 + 1
pdl> print $b->aspdl
Code: Select all
[
[3 3 3]
[3 3 3]
]
7. have fun with MXNet