caffe 安装常见问题

protobuf 版本问题

错误信息

.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::Message::InitializationErrorString() const’

解决方案

  1. 卸载原有protobuf
1
sudo apt-get autoremove libprotobuf-dev protobuf-compiler

2.1 手工编译protobuf 2.5版本

1
2
3
4
5
6
7
8
wget http://protobuf.googlecode.com/files/protobuf-2.5.0.tar.gz  
tar zxvf protobuf-2.5.0.tar.gz
cd protobuf-2.5.0
./configure --prefix=/usr/local/ CC=/usr/bin/gcc
make
make check
make install
protoc --version

2.2 使用protobuf 3.2版本

1
2
INCLUDE_DIRS := /usr/local/protobuf-3.2/include
LIBRARY_DIRS := /usr/local/protobuf-3.2/lib

卸载opencv

1
sudo make uninstall

查看opencv 版本

1
pkg-config --modversion opencv

安装cuda .61

1
https://developer.nvidia.com/cuda-downloads

cv::imread

###

1
2
3
LIBRARIES += glog gflags protobuf leveldb snappy \
lmdb boost_system boost_filesystem hdf5_hl hdf5 m \
opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs opencv_videoio

cuda相关问题

错误信息

1
2
3
./include/caffe/util/cudnn.hpp: In function ‘void caffe::cudnn::createPoolingDesc(cudnnPoolingStruct**, caffe::PoolingParameter_PoolMethod, cudnnPoolingMode_t*, int, int, int, int, int, int)’:
./include/caffe/util/cudnn.hpp:127:41: error: too few arguments to function ‘cudnnStatus_t cudnnSetPooling2dDescriptor(cudnnPoolingDescriptor_t, cudnnPoolingMode_t, cudnnNanPropagation_t, int, int, int, int, int, int)’
pad_h, pad_w, stride_h, stride_w));

解决方案

在Makefile.config 中指定cuda 位置

1
CUDA_DIR := /usr/local/cuda-8.0.61

安装cudnn

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#解压文件
tar -zxvf cudnn-6.5-linux-x64-v2.tgz
#切换路径
cd cudnn-6.5-linux-x64-v2
#复制lib文件到cuda安装路径下的lib64/
sudo cp lib* /usr/local/cuda/lib64/
#复制头文件
sudo cp cudnn.h /usr/local/cuda/include/

#更新软连接
cd /usr/local/cuda/lib64/
sudo rm -rf libcudnn.so libcudnn.so.6.5
sudo ln -s libcudnn.so.6.5.48 libcudnn.so.6.5
sudo ln -s libcudnn.so.6.5 libcudnn.so

faster rcnn 安装

1
2
3
4
5
6
7
8
9
10
git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git
cd py-faster-rcnn
make -j30
cd ../caffe-fast-rcnn
make -j30 && make pycaffe

cd caffe-fast-rcnn
git remote add caffe https://github.com/BVLC/caffe.git
git fetch caffe
git merge -X theirs caffe/master

编译缺 hdf5

1
2
3
sudo apt-get install libhdf5-serial-dev 
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

问题.build_release/lib/libcaffe.so: undefined reference to `cv::imread(cv::String const&, int)’

I think you may be using OpenCV 3. You need to set the OPENCV_VERSION variable in Makefile.config.

👍 18 🎉 5

CMakeList.txt 配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
SET(CMAKE_BUILD_TYPE "Debug")
SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g2 -ggdb")
SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")
macro(use_cxx11)
if (CMAKE_VERSION VERSION_LESS "3.1")
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set (CMAKE_CXX_FLAGS "--std=gnu++11 ${CMAKE_CXX_FLAGS}")
endif ()
else ()
set (CMAKE_CXX_STANDARD 11)
endif ()
endmacro(use_cxx11)
use_cxx11()
set(CUDA_USE_STATIC_CUDA_RUNTIME OFF)

cmake_minimum_required(VERSION 2.8)
set(OpenCV_DIR "/home/opencv-2.4.13/release/")
project( DisplayImage )
find_package( OpenCV REQUIRED )
add_executable( DisplayImage mainmy.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} opencv_imgcodecs opencv_videoio opencv_imgproc opencv_highgui opencv_core opencv_dep_cudart)
message(STATUS $ENV{OpenCV_LIBS})


set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.58.0 COMPONENTS filesystem system)
if (Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(DisplayImage ${Boost_LIBRARIES})
endif()

python 切换版本

1
2
3
4
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 2 # 添加Python2可选项,优先级为2
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.4 1 #添加Python3可选项,优先级为1
sudo update-alternatives --config python
$ python --version

vimrc

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
syntax enable
set background=dark
let g:solarized_termcolors=256
colorscheme solarized

set nocompatible " be iMproved, required
filetype off " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin('~/.vim/plugins')
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'

Plugin 'Lokaltog/vim-powerline'

"Plugin 'Valloric/YouCompleteMe'
"Plugin 'Shougo/neocomplcache.vim'

Plugin 'scrooloose/nerdtree'

Plugin 'scrooloose/nerdcommenter'
" The following are examples of different formats supported.
" Keep Plugin commands between vundle#begin/end.
" plugin on GitHub repo
" Plugin 'tpope/vim-fugitive'
" plugin from http://vim-scripts.org/vim/scripts.html
" Plugin 'L9'
" Git plugin not hosted on GitHub
" Plugin 'git://git.wincent.com/command-t.git'
" git repos on your local machine (i.e. when working on your own plugin)
" Plugin 'file:///home/gmarik/path/to/plugin'
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
" Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" Install L9 and avoid a Naming conflict if you've already installed a
" different version somewhere else.
" Plugin 'ascenator/L9', {'name': 'newL9'}

" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList - lists configured plugins
" :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line
map <F3> :NERDTreeToggle<CR>


set number
set history=1000
set tabstop=4
set cindent
set autoindent
set sts=4
set sw=4
set ts=4
"set showmatch
set syntax=on
let mapleadeer=","
set timeout timeoutlen=1500

"=====================
"let g:complcache_enable_at_startup = 1
"let g:neocomplcache_force_overwrite_completefunc = 1
"


""Note: This option must set it in .vimrc(_vimrc). NOT IN .gvimrc(_gvimrc)!
"" Disable AutoComplPop.
"let g:acp_enableAtStartup = 0
"" Use neocomplcache.
"let g:neocomplcache_enable_at_startup = 1
"" Use smartcase.
"let g:neocomplcache_enable_smart_case = 1
"" Set minimum syntax keyword length.
"let g:neocomplcache_min_syntax_length = 3
"let g:neocomplcache_lock_buffer_name_pattern = '\*ku\*'

"" Enable heavy features.
"" Use camel case completion.
""let g:neocomplcache_enable_camel_case_completion = 1
"" Use underbar completion.
""let g:neocomplcache_enable_underbar_completion = 1

"" Define dictionary.
"let g:neocomplcache_dictionary_filetype_lists = {
" \ 'default' : '',
" \ 'vimshell' : $HOME.'/.vimshell_hist',
" \ 'scheme' : $HOME.'/.gosh_completions'
" \ }

"" Define keyword.
"if !exists('g:neocomplcache_keyword_patterns')
" let g:neocomplcache_keyword_patterns = {}
"endif
"let g:neocomplcache_keyword_patterns['default'] = '\h\w*'

"" Plugin key-mappings.
"inoremap <expr><C-g> neocomplcache#undo_completion()
"inoremap <expr><C-l> neocomplcache#complete_common_string()

"" Recommended key-mappings.
"" <CR>: close popup and save indent.
"inoremap <silent> <CR> <C-r>=<SID>my_cr_function()<CR>
"function! s:my_cr_function()
" return neocomplcache#smart_close_popup() . "\<CR>"
" " For no inserting <CR> key.
" "return pumvisible() ? neocomplcache#close_popup() : "\<CR>"
"endfunction
"" <TAB>: completion.
"inoremap <expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>"
"" <C-h>, <BS>: close popup and delete backword char.
"inoremap <expr><C-h> neocomplcache#smart_close_popup()."\<C-h>"
"inoremap <expr><BS> neocomplcache#smart_close_popup()."\<C-h>"
"inoremap <expr><C-y> neocomplcache#close_popup()
"inoremap <expr><C-e> neocomplcache#cancel_popup()
"" Close popup by <Space>.
""inoremap <expr><Space> pumvisible() ? neocomplcache#close_popup() : "\<Space>"

"" For cursor moving in insert mode(Not recommended)
""inoremap <expr><Left> neocomplcache#close_popup() . "\<Left>"
""inoremap <expr><Right> neocomplcache#close_popup() . "\<Right>"
""inoremap <expr><Up> neocomplcache#close_popup() . "\<Up>"
""inoremap <expr><Down> neocomplcache#close_popup() . "\<Down>"
"" Or set this.
""let g:neocomplcache_enable_cursor_hold_i = 1
"" Or set this.
""let g:neocomplcache_enable_insert_char_pre = 1

"" AutoComplPop like behavior.
""let g:neocomplcache_enable_auto_select = 1

"" Shell like behavior(not recommended).
""set completeopt+=longest
""let g:neocomplcache_enable_auto_select = 1
""let g:neocomplcache_disable_auto_complete = 1
""inoremap <expr><TAB> pumvisible() ? "\<Down>" : "\<C-x>\<C-u>"

"" Enable omni completion.
"autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS
"autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags
"autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
"autocmd FileType python setlocal omnifunc=pythoncomplete#Complete
"autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags

"" Enable heavy omni completion.
"if !exists('g:neocomplcache_force_omni_patterns')
" let g:neocomplcache_force_omni_patterns = {}
"endif
"let g:neocomplcache_force_omni_patterns.php = '[^. \t]->\h\w*\|\h\w*::'
"let g:neocomplcache_force_omni_patterns.c = '[^.[:digit:] *\t]\%(\.\|->\)'
"let g:neocomplcache_force_omni_patterns.cpp = '[^.[:digit:] *\t]\%(\.\|->\)\|\h\w*::'

"" For perlomni.vim setting.
"" https://github.com/c9s/perlomni.vim
"let g:neocomplcache_force_omni_patterns.perl = '\h\w*->\h\w*\|\h\w*::'

cuda .61安装

https://developer.nvidia.com/compute/cuda/8.0/Prod2/local_installers/cuda_8.0.61_375.26_linux-run

查看ip地址

1
ifconfig $1|sed -n 2p|awk  '{ print $2 }'|awk -F : '{ print $2 }'

scp 用法

1
2
3
4
5
6
7
8
1、复制远程服务器的文件到本地:
scp -P888 root@120.18.50.33:/data/ha97.zip /home/
2、复制远程服务器的目录到本地:
scp -vrp -P888 root@120.18.50.33:/data/ha97/ /home/
3、复制本地的文件到远程服务器:
scp -P888 /home/ha97.zip root@120.18.50.33:/data/
4、复制本地的目录到远程服务器:
scp -vrp -P888 /home/ root@120.18.50.33:/data/

参考
http://blog.csdn.net/xuezhisdc/article/details/48651003

请作者喝一杯咖啡☕️