美文网首页macOSMXNET
Mac下编译安装MXNet

Mac下编译安装MXNet

作者: 刀刀宁 | 来源:发表于2016-05-16 08:57 被阅读4640次

    Mac下安装 mxnet 库和基本使用
    官网配置文档

    简单说:

    brew update
    brew tap homebrew/science
    brew info opencv
    brew install opencv
    
    git clone --recursive https://github.com/dmlc/mxnet
    cd mxnet; cp make/osx.mk ./config.mk; make -j4
    

    一定要--recursive,把相关的库一口气都扒下来。

    blas的选项可能需要改一下:

    #USE_BLAS = apple
    USE_BLAS = blas
    ADD_LDFLAGS = -I/usr/local/opt/openblas/lib
    ADD_CFLAGS =  -I/usr/local/opt/openblas/include
    

    坑:

    (该坑是在搞不定openmp不能使用openmp才会遇到)
    当前的版本在MacBook Pro OSX 10.11 EI Captain下有个坑(master commit 7841253)。
    在config.mk里设置为openmp为0的时候,需要注释掉
    dmlc-core/make/dmlc.mk中的:

    ifndef NO_OPENMP
      #DMLC_CFLAGS += -fopenmp
      #DMLC_LDFLAGS += -fopenmp
    endif
    

    或者
    注释掉./Makefile里的:(目前还没明白unexport的用意)

      #unexport NO_OPENMP
    

    否则会报:

    g++ -c -O3 -Wall -msse2  -Wno-unknown-pragmas -Iinclude  -std=c++0x -fopenmp -fPIC -DDMLC_USE_HDFS=0 -DDMLC_USE_S3=0 -DDMLC_USE_AZURE=0 -o line_split.o src/io/line_split.cc
    clang: error: unsupported option '-fopenmp'
    

    另外关于openmp:

    如果是用g++或者g++-5会出现:

    ld: symbol(s) not found for architecture x86_64
    collect2: error: ld returned 1 exit status
    make: *** [bin/im2rec] Error 1
    

    或者

    std::allocator<int> > const&)", referenced from:
          _main in cckUZKeT.o
    ld: symbol(s) not found for architecture x86_64
    collect2: error: ld returned 1 exit status
    

    等错误。(in xxxxxxx.o,xxxx貌似是个随机的,还没搞清楚是什么)

    原因是:mac下默认的gcc不支持openmp,需要用brew安装的gcc才可以用openmp,安装位置在/usr/local/bin/g++-5。而opencv或者其他的部件不是用g++-5来编译安装的造成的。但是g++-5对openmp的支持也有bug。

    更新:
    g++和g++-5对openmp支持都有问题,clang-omp就可以顺利编译。openmp还是很有用的,必须得用上。

    brew install clang-omp
    vim config.mk 
    
    #export CC = gcc
    #export CXX = g++
    #export CC = gcc-5
    #export CXX = g++-5
    export CC = clang-omp
    export CXX = clang-omp++
    
    用上openmp之后的CPU利用率才会突破100%,性能才会大幅提升

    运行mnist

    cd example/image-classification/
    python train_mnist.py
    

    如果报错:

    Traceback (most recent call last):
      File "train_mnist.py", line 132, in <module>
        train_model.fit(args, net, get_iterator(data_shape))
      File "/Users/wszzn/develope/mxnet/example/image-classification/train_model.py", line 85, in fit
        eval_metrics.append(mx.metric.create('top_k_accuracy', top_k = top_k))
    TypeError: create() got an unexpected keyword argument 'top_k'
    

    说明之前通过pip安装过老版本的mxnet python库。卸载即可。

    pip uninstall mxnet
    

    PS:这里给出师弟归整的MXNet样例介绍:[MXnet] Simple Introduction to the Example

    相关文章

      网友评论

      • Catkic:brew install homebrew/boneyard/clamp-omp
        brew install clang-omp

        Error: No available formula with the name "clang-omp"
        ==> Searching for a previously deleted formula...
        Error: No previously deleted formula found.
        ==> Searching for similarly named formulae...
        Error: No similarly named formulae found.
        ==> Searching taps...
        Error: No formulae found in taps.

        安装clang-omp一直失败
      • cptn3m0:按照您的方法, 搞定了mac os上的mxnet 的编译, 已经给社区提了一个pr. 感谢!

      本文标题:Mac下编译安装MXNet

      本文链接:https://www.haomeiwen.com/subject/qyycrttx.html