安装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
解决办法是依据出现错误的顺序而给出的,为了方便,可以直接先执行所有解决办法后再安装caffe。
.
./include/caffe/common.hpp:5:27: fatal error: gflags/gflags.h: No
such file or directory 解决办法:sudo apt-get install libgflags-dev
- ./include/caffe/util/mkl_alternate.hpp:14:19: fatal error: cblas.h: No such file or directory
解决办法: sudo apt-get install libblas-dev .
./include/caffe/util/hdf5.hpp:6:18: fatal error: hdf5.h: No such file
or directory解决办法:在Makefile.config找到以下行并添加蓝色部分
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
/usr/include/hdf5/serialLIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
/usr/lib/x86_64-Linux-gnu/hdf5/serial
- ./include/caffe/util/db_lmdb.hpp:8:18: fatal error: lmdb.h: No such file or directory ```
解决办法:
sudo apt install liblmdb-dev
- /usr/bin/ld: cannot find -lcblas
/usr/bin/ld: cannot find -latlas ```
解决办法:
sudo apt install libatlas-base-dev
caffe /usr/bin/ld: 找不到 -lhdf5_hl
打开Makefile,将第181行的:
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m
hdf5_hlhdf5
改为: LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial opencv_core
opencv_highgui opencv_imgproc opencv_imgcodecs
这里的改动是为了避免出现hdf5.h错误。
- c
affe 找不到hdf5_hl laiyuanyu
http://blog.csdn.net/autocyz/article/details/51783857//重要的一项 将# Whatever else you find you need goes here.下面的
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include LIBRARY_DIRS :=
$(PYTHON_LIB) /usr/local/lib /usr/lib 修改为: INCLUDE_DIRS :=
$(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
/usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial
//这是因为ubuntu16.04的文件包含位置发生了变化,尤其是需要用到的hdf5的位置,所以需要更改这一路径
cd /usr/lib/x86_64-linux-gnu \然后根据情况执行下面两句: sudo ln -s libhdf5_serial.so.10.1.0 libhdf5.so sudo ln -s
libhdf5_serial_hl.so.10.0.2 libhdf5_hl.so
python/caffe/_caffe.cpp:1:52: fatal error: Python.h: No such file or
directory #include <Python.h> // NOLINT(build/include_alpha)
遇到此类问题基本是caffe找不到python,因此在make py之前反复确认下anaconda或python所在目录是否存在。因此需要修改。 本人一直遇到的问题就是因为anaconda安装后 默认的名字为 anaconda2
8.ImportError: /home/meyer/anaconda2/bin/…/lib/libstdc++.so.6: version `GLIBCXX_3.4.20’ not found (required by
/home/meyer/cz/caffe-master/python/caffe/…/…/build/lib/libcaffe.so.1.0.0)
http://blog.csdn.net/lwgkzl/article/details/77658269