caffe安装--踩坑

安装caffe,需要先安装cuda与cudnn,安装cuda之前,需要先安装nvidia的驱动,然后安装opencv,如果能将opencv踩过,那么安装openpose、caffe,我想都没有多大的问题了。
一、官网下载

git clone https://github.com/weiliu89/caffe.git

二、编译

cd caffe
cp Makefile.config.example Makefile.config
mkdir build
cd build
cmake ..
sudo make //首次编译加-j12 ,最好以一个线程编译,方便找问题--踩坑!
sudo make install

三、基本依赖
与opencv一样,需要什么就安装什么,基本上opencv编译过了,相关的依赖的都已经装好了。
四、错误
1、cmake nvcc fatal : Unsupported gpu architecture 'compute_20
根据百度的解决方案是:
注释相关配置行:

CUDA_ARCH := #-gencode arch=compute_20,code=sm_20 \
#-gencode arch=compute_20,code=sm_21 \
-gencode arch=compute_30,code=sm_30 \
-gencode arch=compute_35,code=sm_35 \
-gencode arch=compute_50,code=sm_50 \
-gencode arch=compute_52,code=sm_52 \
-gencode arch=compute_60,code=sm_60 \
-gencode arch=compute_61,code=sm_61 \
-gencode arch=compute_61,code=compute_61
转载:https://blog.csdn.net/tjuyanming/article/details/79249964

但是依旧报错,说明仍是存在其他的编译配置:
最后找到caffe/cmake/Cuda.cmake:

1 if(CPU_ONLY)
  2   return()
  3 endif()
  4 
  5 # Known NVIDIA GPU achitectures Caffe can be compiled for.
  6 # This list will be used for CUDA_ARCH_NAME = All option
  7 #set(Caffe_known_gpu_archs "20 21(20) 30 35 50 52 61")
  8 set(Caffe_known_gpu_archs "30 35 50 52 61")
原文链接:https://blog.csdn.net/fdd096030079/article/details/84451811

2、由于SSD的作者是基于Opencv2.0的环境下写出的SSD源码,而Opencv2和Opencv4的源码又做了比较大的改变,导致编译时会出现像变量没声明的错误,因此需要对以下几个文件进行修改。
错误1:

/src/caffe/layers/video_data_layer.cpp:55:30: error: ‘CV_CAP_PROP_FRAME_COUNT’ was not declared in this scope
     total_frames_ = cap_.get(CV_CAP_PROP_FRAME_COUNT);

解决:
/caffe/src/caffe/layers/video_data_layer.cpp

//加上一个头文件
#include <opencv2/videoio.hpp>
//加上cv命名空间
using namespace cv;
//去掉CV_CAP_PROP_FRAME_COUNT,CV_CAP_PROP_POS_FRAMES前面的CV_
不过建议还是在文件头部进行宏定义:
#define CV_CAP_PROP_FRAME_COUNT CAP_PROP_FRAME_COUNT
#define CV_CAP_PROP_POS_FRAMES   CAP_PROP_POS_FRAMES

错误2:

caffe/src/caffe/layers/window_data_layer.cpp:293:42: error: ‘CV_LOAD_IMAGE_COLOR’ was not declared in this scope
         cv_img = cv::imread(image.first, CV_LOAD_IMAGE_COLOR);

解决:
opencv4里的 CV_LOAD_IMAGE_COLOR 应该使用 cv::IMREAD_COLOR 来代替。同上定义宏,即可。

错误3:

/home/neuron-drop/workspace/caffe/src/caffe/util/bbox_util.cpp:2186:42: error: ‘CV_FILLED’ was not declared in this scope
                   CV_RGB(255, 255, 255), CV_FILLED);

解决:
/caffe/src/caffe/util/bbox_util.cpp

//修改CV_RGB为cv::Scalar,但应该注意两者的区别,前者为RGB,后者为BGR
//修改CV_FILLED为cv::FILLED

错误4:

caffe/src/caffe/util/bbox_util.cpp:2221:48: error: there are no arguments to ‘CV_FOURCC’ that depend on a template parameter, so a declaration of ‘CV_FOURCC’ must be available [-fpermissive]
         cv::VideoWriter outputVideo(save_file, CV_FOURCC('D', 'I', 'V', 'X'),

解决:

cv::VideoWriter writer;
// 修改CV_FOURCC为writer.fourcc

错误5:

caffe/src/caffe/util/im_transforms.cpp:246:39: error: ‘CV_BGR2GRAY’ was not declared in this scope
     cv::cvtColor(in_img, in_img_gray, CV_BGR2GRAY);

解决:

注释掉代码对opencv版本的if判断,并加上以下
#define CV_BGR2HSV cv::COLOR_BGR2HSV
#define CV_HSV2BGR cv::COLOR_HSV2BGR
#define CV_BGR2Lab cv::COLOR_BGR2Lab

错误6:

caffe/src/caffe/util/io.cpp:86:34: error: ‘CV_LOAD_IMAGE_COLOR’ was not declared in this scope
   int cv_read_flag = (is_color ? CV_LOAD_IMAGE_COLOR :
  
  /home/neuron-drop/workspace/caffe/src/caffe/util/io.cpp:87:5: error: ‘CV_LOAD_IMAGE_GRAYSCALE’ was not declared in this scope
     CV_LOAD_IMAGE_GRAYSCALE);

解决:
/home/neuron-drop/workspace/caffe/src/caffe/util/io.cpp

加上
#define CV_LOAD_IMAGE_COLOR cv::IMREAD_COLOR
#define CV_LOAD_IMAGE_GRAYSCALE cv::IMREAD_GRAYSCALE

感兴趣的同学,可以参考opencv4模块的改动:

https://docs.opencv.org/master/d4/da8/group__imgcodecs.html

错误7:

/usr/include/c++/5/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
 #error This file requires compiler and library support \
  ^
CMake Error at cuda_compile_1_generated_detection_output_layer.cu.o.Release.cmake:220 (message):
  Error generating
  /home/neuron-drop/workspace/caffe/build/src/caffe/CMakeFiles/cuda_compile_1.dir/layers/./cuda_compile_1_generated_detection_output_layer.cu.o

解决:
vim CMakeLists.txt

set(CMAKE_CXX_STANDARD 14)
SET( CMAKE_CXX_FLAGS "-std=c++11 -O3")

五、重新编译

cd build
rm * -rf
cmake ..
sudo make -j12
sudo make install 

感谢前人踩坑,提示了我去对应着改动编译代码,否则以我浅薄的C语言知识去解决这个问题怕是遥遥无期了。特此,表示感谢!!
参考:

https://blog.csdn.net/u013915633/article/details/52530130
https://blog.csdn.net/tosonw/article/details/91043145

  • 0
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值