编译环境
win10 x64 、Visual Studio 2015、cmake 3.0+、python2.7 (环境变量需配置)
依赖
1.OpenBLAS-v0.2.14-Win64-int64 下载地址:https://sourceforge.net/projects/openblas/files/v0.2.14/
解压安装后,添加环境变量OpenBLAS_HOME 值为openblas的目录,即:your_dir/openblas
2.OpenCV 3.0+ 下载地址:https://sourceforge.net/projects/opencvlibrary/files/opencv-win/3.3.1/opencv-3.3.1-vc14.exe/download
安装后,添加环境变量OpenCV_DIR 值为your_dir\opencv3.3.1\build,并在path环境变量中添加your_dir\opencv3.3.1\build\x64\vc14\bin
源码编译
1.git clone项目到本地 (版本1.5.1)
git clone --recursive https://github.com/apache/incubator-mxnet mxnet
2.在mxnet目录下创建build目录
3.启动cmake-gui.exe进行mxnet.sln工程的生成
设置mxnet源码路径和mxnet编译路径,点击configure,选择visual studio 2015 win64
生成的配置中,仅仅勾选use_opencv,use_openmp,use_cpp_package即可,如图所示
若提示找不到opencv路径,则手动设置opencv路径即可,如图所示
重新点击configure,配置选项未显示红框且最终信息显示Configuring done,则配置成功
若显示红框,则将显示红框的勾去掉,再重新configure(只保留use_opencv,use_openmp,use_cpp_package的勾选)
点击generate,生成mxnet.sln,生成成功会在build目录下出现mxnet.sln工程,如图所示
拷贝如下dll文件至mxnet\cpp-package\scripts目录下
libopenblas.dll
opencv_world331.dll opencv_ffmpeg331_64.dll
(来自opencv3.3.1安装目录)
libgcc_s_seh-1.dll libgfortran-3.dll libquadmath-0.dll
(来自mingw64_dll 下载地址:https://sourceforge.net/projects/openblas/files/v0.2.14/)
4.利用visual studio 2015 打开mxnet.sln 并执行编译
右键ALL_BUILD,点击生成执行编译,编译成功后会在build/release生成mxnet.lib和mxnet.dll,同时会在mxnet\cpp-package\include\mxnet-cpp生成op.h头文件
如图所示
5.若自动生成op.h头文件失败,则手动生成c++ op.h头文件
重新configure(只保留use_opencv,use_openmp的勾选)再点击generate,生成mxnet.sln 重新利用Visual Studio 2015编译
拷贝如下dll文件至mxnet\cpp-package\scripts目录下
mxnet.dll
libopenblas.dll
opencv_world331.dll opencv_ffmpeg331_64.dll
(来自opencv3.3.1安装目录)
libgcc_s_seh-1.dll libgfortran-3.dll libquadmath-0.dll
(来自mingw64_dll 下载地址:https://sourceforge.net/projects/openblas/files/v0.2.14/)
执行如下命令,生成op.h
python OpWrapperGenerator.py mxnet.dll
错误处理
1.https://github.com/apache/incubator-mxnet/issues/14116
···bash
Build config:
1>——— Build started: Project: cpp_package_op_h, Configuration: Release x64 ———
1>”Running: OpWrapperGenerator.py”
1>D:/Projects/MXNet-versions/MxNet1-3-1/build/Release/libmxnet.dll
1>argument “lrs” of operator “multi_sgd_update” has unknown type “, required”
1>argument “wds” of operator “multi_sgd_update” has unknown type “, required”
1>argument “lrs” of operator “multi_sgd_mom_update” has unknown type “, required”
1>argument “wds” of operator “multi_sgd_mom_update” has unknown type “, required”
1>argument “lrs” of operator “multi_mp_sgd_update” has unknown type “, required”
1>argument “wds” of operator “multi_mp_sgd_update” has unknown type “, required”
1>argument “lrs” of operator “multi_mp_sgd_mom_update” has unknown type “, required”
1>argument “wds” of operator “multi_mp_sgd_mom_update” has unknown type “, required”
========== Build: 1 succeeded, 0 failed, 3 up-to-date, 0 skipped ==========
解决方案:https://github.com/apache/incubator-mxnet/pull/15144/files
本博客所有文章除特别声明外,均采用 CC BY-SA 3.0协议 。转载请注明出处!