这篇博客记录了如何使用BVLC版本的caffe编译windows下的ssd,不喜欢微软版caffe的可以使用这个。
准备工作:
- cmake-gui
- BVLC版本caffe-windows
- Microsoft版本ssd-caffe
1.CPU模式
- 解压BVLC版本caffe-windows。
- 解压Microsoft版本ssd-caffe。
- 进入解压后的caffe-windows,删除include,matlab,models,python,scripts文件夹,并将ssd-caffe下的这几个文件夹复制过来。注意:将ssd-caffe的include复制过来后,删除这个文件夹里面的proto文件夹。
- 在caffe-windows中的include/caffe文件夹下添加一个新文件夹3rdparty,并在这个文件夹下新建一个文件,命名为hungarian.h
- 删除caffe-windows/src/caffe文件夹下所有文件,保留CmakeLiset.txt和caffe-windows/src/caffe/test/CmakeList.txt两个文件。将ssd-caffe下对应的src/caffe文件复制过去。注意不要覆盖两个CmakeList.txt文件。
- 在caffe-windows/src/caffe文件夹下新建一个文件夹3rdparty,进入3rdparty文件夹,新建一个文件,命名为hungarian.cpp
- 修改detection_output_layer.hpp文件,注释掉
- //#include <boost/regex.hpp>
- 修改detection_output_layer.cpp,注释掉
和//boost::regex exp("\"(null|true|false|-?[0-9]+(\\.[0-9]+)?)\"");
/*std::string rv = boost::regex_replace(ss.str(), exp, "$1"); outfile << rv.substr(rv.find("["), rv.rfind("]") - rv.find("[")) << std::endl << "]" << std::endl;*/
- 使用cmake-gui生成解决方案
- 打开解决方案,在caffe工程属性中添加附加包含目录caffe-windows/src,注意:不做这一步编译时候会报错找不到gtest
- 编译caffe工程
- 编译ALL_BUILD工程
- 编译INSTALL工程
2.GPU模式
- 修改bbox_util.cu,注释掉所有带thrust的语句
//#include "thrust/functional.h" //#include "thrust/sort.h"
/*thrust::sort_by_key(&confidences[0], &confidences[0] + num_remain, &idx[0], thrust::greater<Dtype>());*/
- 修改detection_output_layer.cu,注释掉boost::regex的语句
//boost::regex exp("\"(null|true|false|-?[0-9]+(\\.[0-9]+)?)\"");
/*std::string rv = boost::regex_replace(ss.str(), exp, "$1"); outfile << rv.substr(rv.find("["), rv.rfind("]") - rv.find("[")) << std::endl << "]" << std::endl;*/
- 使用cmake生成解决方案
- 打开解决方案,在caffe工程属性中添加附加包含目录caffe-windows/src,注意:不做这一步编译时候会报错找不到gtest
- 编译caffe工程
- 编译ALL_BUILD工程
- 编译INSTALL工程
Q&A
1.错误 2 error LNK2019: 无法解析的外部符号 "public: __cdecl cv::VideoWriter::VideoWriter(class cv::String const &,int,double,class cv::Size_<int>,bool)" (??0VideoWriter@cv@@QEAA@AEBVString@1@HNV?$Size_@H@1@_N@Z),该符号在函数 "void __cdecl caffe::VisualizeBBox<float>(class std::vector<class cv::Mat,class std::allocator<class cv::Mat> > const &,class caffe::Blob<float> const *,float,class std::vector<class cv::Scalar_<double>,class std::allocator<class cv::Scalar_<double> > > const &,class std::map<int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct std::less<int>,class std::allocator<struct std::pair<int const ,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??$VisualizeBBox@M@caffe@@YAXAEBV?$vector@VMat@cv@@V?$allocator@VMat@cv@@@std@@@std@@PEBV?$Blob@M@0@MAEBV?$vector@V?$Scalar_@N@cv@@V?$allocator@V?$Scalar_@N@cv@@@std@@@2@AEBV?$map@HV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@U?$less@H@2@V?$allocator@U?$pair@$$CBHV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@std@@@2@@2@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@@Z) 中被引用
解决:这个错误是链接器里面没有加入opencv的lib导致的。在报错的项目属性中找到链接器--输入。在里面加入xxxxxxxxxxx\opencv_videoio310.lib这个lib,注意写全这个lib的路径。