最近在研究用深度學習預測圖像深度信息的方法,一開始用的是2017年CVPR上Godard大神的monodepth,代碼在這里。這篇文章介紹了利用雙目的consistency訓練網絡以對單張圖像進行深度估計,思路還是蠻有新意的。某天在必應上無意中發現了商湯(sensetime)的Yue Luo同學發表在2018年CVPR上的一篇文章Single View Stereo Matching,代碼開源了,因此fork一下clone下來跑一跑,沒想到按照readme跑第一步installation就遇到了幾個問題,在網上都沒有找到問題的解決辦法,於是自己花了點時間解決了這些問題,特此記錄,以示其他同學。
1.makefile.config缺失問題
原作者給了一個Makefile.config.example,各位同學如果要install的話記得把.example去掉,我們需要的是Makefile.config。
里面的參數是否要取消注釋講的很清楚,我使用了cudnn,因此取消注釋USE_CUDNN := 1。我的opencv版本是3.2.0,因此取消注釋OPENCV_VERSION := 3。對於CUDA_ARCH,如果你的CUDA版本比較高,建議你刪掉compute_20和compute_21這兩行。然后就是一些引用庫的路徑,后面會說到。
2.缺少hdf5.h問題
首先安裝hdf5,你需要在官網下載hdf5,然后解壓編譯安裝
$ cd hdf5-1.10.3
$ mkdir build
$ cd build
$ cmake ..
$ sudo make
$ sudo make install
如果遇到問題,我的另一篇文章里介紹了如何解決hdf5的安裝問題。
安裝好了hdf5之后,需要在Makefile.config里加入鏈接,以保證可以調用hdf5的庫。對於我來說,我需要在這里加
HDF5_DIRS :=/home/yao/Environment/hdf5-1.10.3/hdf5
OpenCV_DIR :=/home/yao/Environment/opencv-3.2.0/build
我順便加了一個OpenCV的路徑,以防需要。同學們把前面的路徑改成自己的路徑即可。然后將下面的兩行
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
改為
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include $(HDF5_DIRS)/include $(OpenCV_DIR)/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib $(HDF5_DIRS)/lib $(OpenCV_DIR)/lib
3.cudnn版本的問題
make的時候發現了如下的問題
In file included from ./include/caffe/util/device_alternate.hpp:40:0,
from ./include/caffe/common.hpp:19,
from src/caffe/syncedmem.cpp:1:
./include/caffe/util/cudnn.hpp: In function ‘void caffe::cudnn::setConvolutionDesc(cudnnConvolutionStruct**, cudnnTensorDescriptor_t, cudnnFilterDescriptor_t, int, int, int, int)’:
./include/caffe/util/cudnn.hpp:112:3: error: too few arguments to function ‘cudnnStatus_t cudnnSetConvolution2dDescriptor(cudnnConvolutionDescriptor_t, int, int, int, int, int, int, cudnnConvolutionMode_t, cudnnDataType_t)’
CUDNN_CHECK(cudnnSetConvolution2dDescriptor(*conv,
^
In file included from ./include/caffe/util/cudnn.hpp:5:0,
from ./include/caffe/util/device_alternate.hpp:40,
from ./include/caffe/common.hpp:19,
from src/caffe/syncedmem.cpp:1:
/usr/local/cuda/include/cudnn.h:537:27: note: declared here
cudnnStatus_t CUDNNWINAPI cudnnSetConvolution2dDescriptor( cudnnConvolutionDescriptor_t convDesc,
^
Makefile:579: recipe for target '.build_release/src/caffe/syncedmem.o' failed
make: *** [.build_release/src/caffe/syncedmem.o] Error 1
make: *** Waiting for unfinished jobs....
在網上看了一下,是這份代碼提供的cudnn版本太老,從別的caffe里比如caffe/include/caffe/util復制cudnn.hpp到SVS/caffe/include/caffe/util/目錄下,即可解決。
4.src/caffe/util/util_img.cpp中caffe::BlobToGrayImage函數的問題
接下來的幾步的問題都比較隱蔽,要在命令行的編譯結果里仔細找才能看到。這一步的問題我在github的issue里也看到了,好幾個人都在討論怎么解決,大家沒什么辦法,作者似乎也不太清楚怎么回事,我自己研究了一下,解決了這個問題,還是比較有成就感的。
這一步的主要問題如下
src/caffe/util/util_img.cpp: At global scope: src/caffe/util/util_img.cpp:709:33: error: redeclaration of ‘template<class Dtype> cv::Mat caffe::BlobToGrayImage(const caffe::Blob<Dtype>*, int, int, Dtype)’ may not have default arguments [-fpermissive] const Dtype scale = Dtype(1.0)) { ^ Makefile:595: recipe for target '.build_release/src/caffe/util/util_img.o' failed make: *** [.build_release/src/caffe/util/util_img.o] Error 1 make: *** Waiting for unfinished jobs....
我們找到這個cpp,打開移動到709行,發現函數定義如下
template <typename Dtype> cv::Mat BlobToGrayImage(const Blob<Dtype>* blob, const int n, const int c, const Dtype scale = Dtype(1.0))
報的錯是對於Dtype(1.0)這個賦值,我們在函數里找一找scale這個變量,發現只用到了一處
v1 *= scale;
按照原定義的1.0,這里相當於什么都沒有做,為了解決這個問題,我們直接刪掉初始化,將定義改為
template <typename Dtype> cv::Mat BlobToGrayImage(const Blob<Dtype>* blob, const int n, const int c, const Dtype scale)
然后將用到scale的句子屏蔽
//v1 *= scale;
即可解決此問題。
5.不支持compute_20的問題
問題顯示如下
NVCC src/caffe/solvers/nesterov_solver.cu
nvcc fatal : Unsupported gpu architecture 'compute_20'
Makefile:608: recipe for target '.build_release/cuda/src/caffe/solvers/nesterov_solver.o' failed
make: *** [.build_release/cuda/src/caffe/solvers/nesterov_solver.o] Error 1
make: *** Waiting for unfinished jobs....
這個是因為你的cuda版本比較新,不支持compute_20,因此需要你刪掉compute_20和compute_21這兩行,即可解決。
6.gpumat.hpp缺失
這個問題比較少見,網上沒有找到答案,甚至這個hpp文件官方都沒有適合的,問題如下
In file included from src/caffe/layers/resample_layer.cu:11:0:
./include/thirdparty/gpu/gpu.hpp:52:35: fatal error: opencv2/core/gpumat.hpp: No such file or directory
compilation terminated.
Makefile:608: recipe for target '.build_release/cuda/src/caffe/layers/resample_layer.o' failed
make: *** [.build_release/cuda/src/caffe/layers/resample_layer.o] Error 1
make: *** Waiting for unfinished jobs...
這是沒有找到gpu_mat.hpp這個文件,我去OpenCV里找了找,有兩個叫這個名字的文件,不過不是/opencv2/core/文件夾下的,試着在gpu.hpp里改一下頭文件的引用位置,改成OpenCV里的那兩個文件,都會報如下的錯誤
./include/thirdparty/gpu/gpu.hpp(161): error: identifier "GpuMat" is undefined
說明這兩個頭文件不是我們需要的,沒辦法,只能在網上找找了,果然找到了一個github中有,大概看了一眼,貌似是因為OpenCV2中的文件,看來是OpenCV3改動比較大。於是我直接在/usr/local/include/opencv2/core文件夾里面創建了一個gpumat.hpp文件,然后把這個文件的內容復制進去即可,記得加sudo權限。
7.cuda_devptrs.hpp缺失
這個問題跟上面的問題一樣,也需要一個新的hpp頭文件,我們在網上找到了另一個github,相似的操作,同樣的位置直接創建一個cuda_devptrs.hpp文件,然后復制進去。
NVCC src/caffe/layers/resample_layer.cu
In file included from ./include/thirdparty/gpu/gpu.hpp:52:0,
from src/caffe/layers/resample_layer.cu:11:
/usr/local/include/opencv2/core/gpumat.hpp:49:41: fatal error: opencv2/core/cuda_devptrs.hpp: No such file or directory
compilation terminated.
Makefile:608: recipe for target '.build_release/cuda/src/caffe/layers/resample_layer.o' failed
make: *** [.build_release/cuda/src/caffe/layers/resample_layer.o] Error 1
8.vector沒有聲明std空間
不知道是不是作者粗心,gpu.hpp里調用了vector,卻沒有在前面加上std::或者在最前面聲明using namespace std;結果產生如下錯誤
./include/thirdparty/gpu/gpu.hpp(432): error: vector is not a template
太多vector了,不可能一個個加,雖然我很不情願,但我只能在最前面加一個using namespace std;了,希望作者下次用心,也不知道他是怎么調通的。
9.編譯boost
有些地方可能需要boost這個庫,而較新的代碼都是用c++14編譯才能不報錯,因此我們先在官網下載boost,然后編譯
$ cd boost_1_69_0
$ ./bootstrap.sh
$ ./b2 cxxflags="--std=c++14" -j12
$ sudo ./b2 install
生成的庫位於/usr/local/lib目錄,默認的頭文件在/usr/local/include/boost目錄。