之前编译的是caffe python2.7版本,与caffe python3.5版本还是有差异,记录一下。

下载 caffe windows版本:https://github.com/BVLC/caffe/tree/windows

前提:已安装 anaconda 3(python 3.5),VS2015,CMake,CUDA8.0+cudnn5.1

一 caffe-windows\scripts路径下修改配置文件build_win.cmd

caffe python3.5 Windows版本编译

如上图, 根据提示VS、Python版本修改为相应的版本号(MSVC_VERSION=14:VS2015;PYTHON_VERSION=3:Python3.5);CPU_ONLY=0:GPU。

修改好build_win.cmd文件,可以打开CMake进行配置生成caffe的VS项目了(也可直接输入命令.\scripts\build_win.cmd)

CMake中,如下图,source code位置为caffe路径,build为新建的生成文件路径,下图红圈圈处BLAS其Value由Atlas改为Open,否则会出现“Could NOT find Atlas...”的错误。点击Configure,CMake会下载相应的依赖包libraries_v140_x64_py35_1.1.0.tar.bz2到C:\Users\XX\.caffe\dependencies\download下,编译时会到dependencies找相应的包(例如BLAS会调用openblas的包),配置成功,再点击Generate,完成。得到caffe的解决方案Caffe.sln。

caffe python3.5 Windows版本编译

三 VS编译caffe

caffe python3.5 Windows版本编译

以ALL_BUILD为启动项,配置:Release+x64,编译整个工程,完成。

caffe python3.5 Windows版本编译

可以在 caffe-windows\build\tools\Release 下调用相应的可执行文件了

caffe python3.5 Windows版本编译

四 python中调用caffe

Caffe.sln中pycaffe编译好之后,在caffe-windows\python目录下会生成caffe文件夹,将其拷贝到Anaconda3\Lib\site-packages目录下。此时在Spyder中调用应能成功调用caffe。

caffe python3.5 Windows版本编译

然而:import caffe 时出现了 from numpy.lib.arraypad import _validate_lengths, ImportError: cannot import name '_validate_lengths'的错误,应该是scikit-image包的问题,对其更新 pip install --upgrade scikit-image之后,又出现caffe cannot import name 'img_as_float32',直接pip uninstall 再install scikit-image,此时import caffe成功。

分类:

技术点:

相关文章: