原文鏈接:
http://mxnet.io/get_started/centos_setup.html
MXNet currently supports Python, R, Julia, and Scala. For users on CentOS with Docker environment, MXNet providesDocker installation guide. If you do not have a Docker environment set up, follow below-provided step by step instructions.
Make sure you have the root permission, andyumis properly installed. Check it using the following command:
sudo yum check-update
If you don’t get an error message, thenyumis installed.
To install MXNet on CentOS, you must have the following:
gcc, g++ (4.8 or later)
python2, python-numpy, python-pip, clang
graphviz, jupyter (pip or yum install)
OpenBLAS
CUDA for GPU
cmake and opencv (do not use yum to install opencv, some shared libs may not be installed)
Make sure your machine is connected to Internet. A few installations need to download (gitcloneorwget) some packages from Internet.
# Install gcc-4.8/make and other development toolssudo yum install -y gcc? ? sudo yum install -y gcc-c++? ? sudo yum install -y clang# Install Python, Numpy, pip and set up tools.sudo yum groupinstall -y"Development Tools"sudo yum install -y python27 python27-setuptools python27-tools python-pip? ? sudo yum install -y python27-numpy# install graphviz, jupytersudo pip install graphviz? ? sudo pip install jupyter
Note that OpenBLAS can be replaced by other BLAS libs, e.g, Intel MKL.
# Install OpenBLAS at /usr/local/openblasgit clone https://github.com/xianyi/OpenBLAScdOpenBLAS? ? make -j$(($(nproc)+1))sudo makePREFIX=/usr/local installcd..
Note: Setting up CUDA is optional for MXNet. If you do not have a GPU machine (or if you want to train with CPU), you can skip this section and proceed with installation of OpenCV.
If you plan to build with GPU, you need to set up the environment for CUDA and CUDNN.
First, download and installCUDA 8 toolkit.
Then downloadcudnn 5.
Unzip the file and change to the cudnn root directory. Move the header and libraries to your local CUDA Toolkit folder:
tar xvzf cudnn-8.0-linux-x64-v5.1-ga.tgz? ? sudo cp -P cuda/include/cudnn.h /usr/local/cuda/include? ? sudo cp -P cuda/lib64/libcudnn* /usr/local/cuda/lib64? ? sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*? ? sudo ldconfig
Note: Setting up opencv is optional but strongly recommended for MXNet, unless you do not want to work on Computer Vision and Image Augmentation. If you are quite sure about that, skip this section and setUSE_OPENCV=0inconfig.mk.
The Open Source Computer Vision (OpenCV) library contains programming functions for computer vision and image augmentation. For more information, seeOpenCV.
# Install cmake for building opencvsudo yum install -y cmake# Install OpenCV at /usr/local/opencvgit clone https://github.com/opencv/opencvcdopencv? ? mkdir -p buildcdbuild? ? cmake -DBUILD_opencv_gpu=OFF -DWITH_EIGEN=ON -DWITH_TBB=ON -DWITH_CUDA=OFF -DWITH_1394=OFF -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/usr/local ..? ? sudo makePREFIX=/usr/local install
After installing the dependencies, use the following command to pull the MXNet source code from GitHub.
# Download MXNet source code to ~/mxnet directorygit clone https://github.com/dmlc/mxnet.git ~/mxnet --recursive# Move to source code parent directorycd~/mxnet? ? cp make/config.mk .# Replace this line if you use other BLAS libsecho"USE_BLAS=openblas">>config.mkecho"ADD_CFLAGS += -I/usr/include/openblas">>config.mkecho"ADD_LDFLAGS += -lopencv_core -lopencv_imgproc -lopencv_imgcodecs">>config.mk
If building withGPUsupport, run below commands to add GPU dependency configurations toconfig.mkfile:
echo"USE_CUDA=1">>config.mkecho"USE_CUDA_PATH=/usr/local/cuda">>config.mkecho"USE_CUDNN=1">>config.mk
Then build mxnet:
make -j$(nproc)
Executing these commands creates a library calledlibmxnet.soin~/mxnet/lib/.
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 MXNet for R, Julia and Scala
Here is some information to help you troubleshoot, in case you encounter error messages:
1. Cannot build opencv from source code
This may be caused by download failure during building, e.g.,ippicv.
Prepare some large packages by yourself, then copy them to the right place, e.g,opencv/3rdparty/ippicv/downloads/linux-808XXXXXXXXX/.
2. Link errors when building MXNet
/usr/bin/ld: /tmp/ccQ9qruP.o: undefined reference to symbol'_ZN2cv6String10deallocateEv'/usr/local/lib/libopencv_core.so.3.2: error adding symbols: DSO missing fromcommandline
This error occurs when you already have old opencv (e.g, 2.4) installed usingyum(in/usr/lib64). When g++ tries to link opencv libs, it will first find and link old opencv libs in/usr/lib64.
Please modifyconfig.mkinmxnetdirectory, and add-L/usr/local/libtoADD_CFLAGS.
ADD_CFLAGS +=-I/usr/include/openblas -L/usr/local/lib
This solution solves this link error, but there are still lots of warnings.