Ubuntu上編譯Caffe和拓展應用(faster-rcnn, pvanet)的錯誤及解決方案
Caffe
錯誤: 採用make方式編譯時遇到如下錯誤
In file included from /usr/include/boost/python/detail/prefix.hpp:13:0,
from /usr/include/boost/python/args.hpp:8,
from /usr/include/boost/python.hpp:11,
from tools/caffe.cpp:2:
/usr/include/boost/python/detail/wrap_python.hpp:50:23: fatal error: pyconfig.h: No such file or directory
compilation terminated.
Makefile:575: recipe for target '.build_release/tools/caffe.o' failed
make: *** [.build_release/tools/caffe.o] Error 1
解決方案:修改Makefile.config,將
PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
# $(ANACONDA_HOME)/include/python2.7 \
# $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include \
取消以下2行註釋
PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
$(ANACONDA_HOME)/include/python2.7 \
$(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include \
Note:$(ANACONDA_HOME) #虛擬環境Anaconda2的根目錄
Faster-RCNN
問題: 如何編譯只採用cpu版本的Faster-RCNN?
解決方案:
在./lib/setup.py中註釋以下部分
...
#CUDA = locate_cuda()
...
...
#self.set_executable('compiler_so', CUDA['nvcc'])
...
...
#Extension('nms.gpu_nms',
#[‘nms/nms_kernel.cu', 'nms/gpu_nms.pyx'],
#library_dirs=[CUDA['lib64']],
#libraries=['cudart'],
#language='c++',
#runtime_library_dirs=[CUDA['lib64']],
## this syntax is specific to this build system
## we're only going to use certain compiler args with nvcc and not with
## gcc the implementation of this trick is in customize_compiler() below
#extra_compile_args={'gcc': ["-Wno-unused-function"],
#’nvcc': ['-arch=sm_35',
#’—ptxas-options=-v',
#’-c’,
#’—compiler-options',
#”’-fPIC'"]},
#include_dirs = [numpy_include, CUDA['include']]
#)
問題:執行時,遇到錯誤:ImportError: No module named cv2
File "./tools/test_net.py", line 13, in <module>
from fast_rcnn.test import test_net
File "/home/rtc5/JpHu/pva-faster-rcnn-master/tools/../lib/fast_rcnn/test.py", line 15, in <module>
import cv2
ImportError: No module named cv2
解決方案
(1)檢查cv2是否存在:
在${HOME}
目錄下執行
$find -name cv2
進行查詢
(2)如果不存在cv2,安裝python-opencv
sudo apt-get install python-opencv
(3)如果存在cv2,將資料夾cv2所在目錄新增到.bashrc最後一行(如我將cv2安裝在/home/rtc5/anaconda2/envs/tensorflow/lib/python2.7/site-packages/cv2
下)
export PATHONPATH=$PYTHONPATH:/home/rtc5/anaconda2/envs/tensorflow/lib/python2.7/site-packages/cv2
執行命令
source ./bashrc #啟用
啟用./bashrc
問題:編譯cpu版本成功後,faster-rcnn執行時,遇到錯誤ImportError: No module named gpu_nms
File "./demo.py", line 18, in
from fast_rcnn.test import im_detect
File ".../py-faster-rcnn-master/tools/../lib/fast_rcnn/test.py", line 17, in
from fast_rcnn.nms_wrapper import nms
File ".../py-faster-rcnn-master/tools/../lib/fast_rcnn/nms_wrapper.py", line 11, in
from nms.gpu_nms import gpu_nms
ImportError: No module named gpu_nms
解決方案:
註釋${FCNN}/py-faster-rcnn/lib/fast_rcnn/nms_wrapper.py
中有關gpu的程式碼
from fast_rcnn.config import cfg
#from nms.gpu_nms import gpu_nms
from nms.cpu_nms import cpu_nms
def nms(dets, thresh, force_cpu=False):
"""Dispatch to either CPU or GPU NMS implementations."""
if dets.shape[0] == 0:
return []
#if cfg.USE_GPU_NMS and not force_cpu:
# return gpu_nms(dets, thresh, device_id=cfg.GPU_ID)
else:
return cpu_nms(dets, thresh)
問題:(1)執行vgg16版本的faster-rcnn的./tools/demo.py
遇到如下問題
WARNING: Logging before InitGoogleLogging() is written to STDERR
F1207 00:08:31.251930 20944 common.cpp:66] Cannot use GPU in CPU-only Caffe: check mode.
*** Check failure stack trace: ***
Aborted (core dumped)
解決方案:
採用命令:
$./tools/demo.py --cpu
Note:執行pvanet示例時,遇到類似問題,則需要將測試檔案*.py中set_gpu的相關程式碼註釋
問題:如何編譯cpu版本的pvanet
編譯caffe,遇到問題:
src/caffe/layers/proposal_layer.cpp:321:10: error: redefinition of ‘void caffe::ProposalLayer<Dtype>::Backward_gpu(const std::vector<caffe::Blob<Dtype>*>&, const std::vector<bool>&, const std::vector<caffe::Blob<Dtype>*>&)’
STUB_GPU(ProposalLayer);
^
./include/caffe/util/device_alternate.hpp:17:6: note: in definition of macro ‘STUB_GPU’
void classname<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top, \
^
In file included from src/caffe/layers/proposal_layer.cpp:1:0:
./include/caffe/fast_rcnn_layers.hpp:122:16: note: ‘virtual void caffe::ProposalLayer<Dtype>::Backward_gpu(const std::vector<caffe::Blob<Dtype>*>&, const std::vector<bool>&, const std::vector<caffe::Blob<Dtype>*>&)’ previously declared here
virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,
^
Makefile:575: recipe for target '.build_release/src/caffe/layers/proposal_layer.o' failed
make: *** [.build_release/src/caffe/layers/proposal_layer.o] Error 1
make: *** Waiting for unfinished jobs....
解決方案:
由於caffe::ProposalLayer<Dtype>::Backward_gpu
在./include/caffe/fast_rcnn_layers.hpp
和./include/caffe/util/device_alternate.hpp
(後者為模板形式)中定義了兩次,被系統認為重定義。
解決方法如下:
將./include/caffe/fast_rcnn_layers.hpp
的Backward_gpu
程式碼
virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,
const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom){}
修改如下
virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,
const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);
由於Backward_cpu
只在./include/caffe/fast_rcnn_layers.hpp
中定義過一次,所以一定避免對它做如上gpu的修改。
問題:如何只用cpu訓練caffe,py-faster-rcnn,pvanet?
*報錯:
smooth_L1_loss_layer Not Implemented Yet
解決方案:*
補充./src/caffe/layers/smooth_L1_loss_layer.cpp函式實體SmoothL1LossLayer::Forward_cpu和SmoothL1LossLayer::Backward_cpu
`// ------------------------------------------------------------------
// Fast R-CNN
// Copyright (c) 2015 Microsoft
// Licensed under The MIT License [see fast-rcnn/LICENSE for details]
// Written by Ross Girshick
// ------------------------------------------------------------------
#include "caffe/fast_rcnn_layers.hpp"
namespace caffe {
template
void SmoothL1LossLayer::LayerSetUp(
const vector<Blob>& bottom, const vector<Blob>& top) {
SmoothL1LossParameter loss_param = this->layer_param_.smooth_l1_loss_param();
sigma2_ = loss_param.sigma() * loss_param.sigma();
has_weights_ = (bottom.size() >= 3);
if (has_weights_) {
CHECK_EQ(bottom.size(), 4) << "If weights are used, must specify both "
"inside and outside weights";
}
}
template
void SmoothL1LossLayer::Reshape(
const vector<Blob>& bottom, const vector<Blob>& top) {
LossLayer::Reshape(bottom, top);
CHECK_EQ(bottom[0]->channels(), bottom[1]->channels());
CHECK_EQ(bottom[0]->height(), bottom[1]->height());
CHECK_EQ(bottom[0]->width(), bottom[1]->width());
if (has_weights_) {
CHECK_EQ(bottom[0]->channels(), bottom[2]->channels());
CHECK_EQ(bottom[0]->height(), bottom[2]->height());
CHECK_EQ(bottom[0]->width(), bottom[2]->width());
CHECK_EQ(bottom[0]->channels(), bottom[3]->channels());
CHECK_EQ(bottom[0]->height(), bottom[3]->height());
CHECK_EQ(bottom[0]->width(), bottom[3]->width());
}
diff_.Reshape(bottom[0]->num(), bottom[0]->channels(),
bottom[0]->height(), bottom[0]->width());
errors_.Reshape(bottom[0]->num(), bottom[0]->channels(),
bottom[0]->height(), bottom[0]->width());
// vector of ones used to sum
ones_.Reshape(bottom[0]->num(), bottom[0]->channels(),
bottom[0]->height(), bottom[0]->width());
for (int i = 0; i < bottom[0]->count(); ++i) {
ones_.mutable_cpu_data()[i] = Dtype(1);
}
}
template
void SmoothL1LossLayer::Forward_cpu(const vector<Blob>& bottom,
const vector<Blob>& top) {
// NOT_IMPLEMENTED;
int count = bottom[0]->count();
//int num = bottom[0]->num();
const Dtype* in = diff_.cpu_data();
Dtype* out = errors_.mutable_cpu_data();
caffe_set(errors_.count(), Dtype(0), out);
caffe_sub(
count,
bottom[0]->cpu_data(),
bottom[1]->cpu_data(),
diff_.mutable_cpu_data()); // d := b0 - b1
if (has_weights_) {
// apply "inside" weights
caffe_mul(
count,
bottom[2]->cpu_data(),
diff_.cpu_data(),
diff_.mutable_cpu_data()); // d := w_in * (b0 - b1)
}
for (int index = 0;index < count; ++index){
Dtype val = in[index];
Dtype abs_val = abs(val);
if (abs_val < 1.0 / sigma2_) {
out[index] = 0.5 * val * val * sigma2_;
} else {
out[index] = abs_val - 0.5 / sigma2_;
}
}
if (has_weights_) {
// apply "outside" weights
caffe_mul(
count,
bottom[3]->cpu_data(),
errors_.cpu_data(),
errors_.mutable_cpu_data()); // d := w_out * SmoothL1(w_in * (b0 - b1))
}
Dtype loss = caffe_cpu_dot(count, ones_.cpu_data(), errors_.cpu_data());
top[0]->mutable_cpu_data()[0] = loss / bottom[0]->num();
}
template
void SmoothL1LossLayer::Backward_cpu(const vector<Blob>& top,
const vector& propagate_down, const vector<Blob>& bottom) {
// NOT_IMPLEMENTED;
int count = diff_.count();
//int num = diff_.num();
const Dtype* in = diff_.cpu_data();
Dtype* out = errors_.mutable_cpu_data();
caffe_set(errors_.count(), Dtype(0), out);
for (int index = 0;index < count; ++index){
Dtype val = in[index];
Dtype abs_val = abs(val);
if (abs_val < 1.0 / sigma2_) {
out[index] = sigma2_ * val;
} else {
out[index] = (Dtype(0) < val) - (val < Dtype(0));
}
}
for (int i = 0; i < 2; ++i) {
if (propagate_down[i]) {
const Dtype sign = (i == 0) ? 1 : -1;
const Dtype alpha = sign * top[0]->cpu_diff()[0] / bottom[i]->num();
caffe_cpu_axpby(
count, // count
alpha, // alpha
diff_.cpu_data(), // x
Dtype(0), // beta
bottom[i]->mutable_cpu_diff()); // y
if (has_weights_) {
// Scale by "inside" weight
caffe_mul(
count,
bottom[2]->cpu_data(),
bottom[i]->cpu_diff(),
bottom[i]->mutable_cpu_diff());
// Scale by "outside" weight
caffe_mul(
count,
bottom[3]->cpu_data(),
bottom[i]->cpu_diff(),
bottom[i]->mutable_cpu_diff());
}
}
}
}
#ifdef CPU_ONLY
STUB_GPU(SmoothL1LossLayer);
#endif
INSTANTIATE_CLASS(SmoothL1LossLayer);
REGISTER_LAYER_CLASS(SmoothL1Loss);
} // namespace caffe
轉自: zhouphd 的解答,已驗證有效,caffe能夠通過編譯,並進行訓練
問題:執行pvanet時,報錯
Intel MKL FATAL ERROR: Cannot load libmkl_avx2.so or libmkl_def.so.
原因:由於之前安裝tensorflow時,採用的是anaconda,它獨自建立了一個虛擬環境(自行另安裝依賴庫),但由於anaconda會在~/.bashrc中新增PATH路徑。所以執行caffe程式時(在虛擬環境之外),其依賴庫也會受到anaconda安裝軟體的影響。
解決方案:遮蔽anaconda設定的PATH,在~/.bashrc中註釋
#export PATH="/home/cvrsg/anaconda2/bin:$PATH"
$source ~/.bashrc #啟用.bashrc
注意:重開一個終端,在當前終端,source命令是沒有生效的。
如何驗證?
如果在當前終端下輸入
sudo echo $PATH
你會發現anaconda2/bin還在PATH中,source未生效
重開終端之後,
anaconda2/bin已消失
同樣由此可知,當我們需要anaconda2時,我們可以將
#export PATH="/home/cvrsg/anaconda2/bin:$PATH"
解註釋,並source ~/.bashrc
啟用
不需要時,註釋即可。
在上述命令被註釋的情況下,執行source activate tensorflow
會出現以下錯誤
bash: activate: No such file or directory
彆著急,解註釋,啟用就好。
Note-切記:::
另外,如果我們要用conda安裝軟體時,一定要切換到相應的虛擬環境下,否則安裝的軟體很容易和系統軟體發生版本衝突,導致程式出錯。
在安裝pycaffe依賴庫時,遇到的問題
利用命令for req in $(cat requirements.txt); do pip install $req; done
安裝pycaffe相關依賴庫遇到問題:ImportError: No module named packaging.version
描述:這是因為採用 sudo apt-get install python-pip
安裝的pip有問題
sudo apt-get remove python-pip #刪除原有pip
wget https://bootstrap.pypa.io/get-pip.py //獲取特定pip,並進行安裝
sudo python get-pip.py
錯誤
F0608 15:36:07.750129 6353 concat_layer.cpp:42] Check failed: top_shape[j] == bottom[i]->shape(j) (63 vs. 62) All inputs must have the same shape, except at concat_axis.
*** Check failure stack trace: ***
Aborted (core dumped)
這個似乎是新版本的PVANET的問題,舊版本的PVANET沒有該問題。問題出在lib檔案的改變。
其他
問題: wget如何避免防火牆的影響?
解決方案:
在命令
wget xxx
#如wget https://www.dropbox.com/s/87zu4y6cvgeu8vs/test.model?dl=0 -O models/pvanet/full/test.model
之後加
—no-check-certificate
相關推薦
Ubuntu上編譯Caffe和拓展應用(faster-rcnn, pvanet)的錯誤及解決方案
Caffe 錯誤: 採用make方式編譯時遇到如下錯誤 In file included from /usr/include/boost/python/detail/prefix.hpp:13:0, fr
ubuntu 14.04+caffe +cuda7.5+cuDNN+faster-RCNN
前言: 剛開始接觸機器學習,遇到了很多的問題,也是在前人的部落格的幫助下一步步學習起來的,所以寫下本文,傳遞知識。 摘要: 本文主要實在ubuntu14.04下搭建caffe,並且執行py-faster-rcnn。用於目標檢
ubuntu上編譯安裝mysql5.7.x【多次錯誤之後總結的方法】
1.進入mysql官網->Downloads->MySQL Community Edition->MySQL Community Server->Select Platform
ubuntu 上Access denied for user 'root'@'localhost' (using password:YES) 的解決方案
在ubuntu系統通過apt-get 安裝好mysql 並且配置好密碼後, 使用這個命令“mysql -uroot -pmyadmin”後出現以下錯誤: “Access denied for user 'root'@'localhost' (using password:Y
[ c++] cmake 編譯時 undefined reference to `std::cout' 錯誤的解決方案
bin cut () cmake fin epo linking com urn cmake .. 和 make 之後,出現如下錯誤 Linking CXX executable ../../../bin/ModuleTest CMakeFiles/Modu
ubuntu環境中搭建java開發環境(含遇到的錯誤及解決辦法)
一.安裝JDK 方法很多,參考網址http://blog.csdn.net/zth1002/article/details/51383508 即可。 注意這裡,在配置好了環境變數之後,可以不用重啟電腦,可以直接source ~/.bashrc使剛剛的修改直接
ubuntu 12.04下安裝軟體報“在處理時有錯誤發生”解決方案
今天剛裝完ubuntu 12.04,想安裝Chrome瀏覽器,在《Ubuntu軟體中心》沒有找到,只有Chromium,於是就先Googling了一下,有人說先在:“直接去官網下的安裝不了,得要先在《Ubuntu軟體中心》安裝Chromium之後,再安裝Chrome,最後再
Android NDK編譯常見錯誤及解決方案
轉自:http://chinavideo.org/forum.php?mod=viewthread&tid=10821&page=1 Error 1: $ ndk-build/cygdrive/c/andy/abc/obj/local/armeabi-v7a
在Ubuntu 11.04環境下搭載Android開發環境若干錯誤的解決方案
1、問題一:手動安裝JDK,需要手動環境變數,配置方法如下(以root使用者名稱的方式進入Ubuntu環境): (1)開啟Terminal(終端),執行cd /,然後執行cd etc/
Ubuntu 14.04 Caffe和TensorFlow的ARM NN SDK編譯環境搭建及MNIST程式測試
Ubuntu 14.04下Caffe和TensorFlow的ARM NN SDK的aarch64編譯環境搭建及MNIST程式測試 ARM官方測試環境 1. SCons安裝 2.安裝CMake 3.下載安裝boost 4.使用 S
PC ubuntu 上編譯qt 並開發樹莓派上的桌面應用
PC ubuntu 上使用qt 開發樹莓派上的桌面應用,從編譯qt原始碼到配置kit,到編譯,到除錯執行測試,再到到寫入樹莓派sdcard 真正的一站式教程,個人覺得這樣的文章對於初學qt和樹莓派的菜鳥們來說,簡直就是福音啊!因為我就是 file:///C:\Users\D\AppData\Local\T
在基於debian的deepin或者Ubuntu上雙等號“==”和雙中括號“[[]]”不能使用的真相
logs deep test [] 發現 不能 腳本 使用 mar 使用的deepin-linux,今天寫shell腳本的時候,忽然發現 sh test.sh 會報錯[[: not found ,雙等號和雙中括號都不能使用了,很郁悶,後來探索發現,sh其實是dash的別名,
在ubuntu上編譯 wpa_supplicant-2.6
wifi wlan 1.1 libnl-3.4.0./configure --prefix=/home/fnie/wpa/out/libnl --disable-static makemake checkmake install// to install the API documentation:m
Ubuntu上編譯安裝Freetype/Freetype-py
分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow 也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!  
ubuntu上安裝caffe
參考:https://blog.csdn.net/Reedlh/article/details/80659363 常用的深度學習框架有 TensorFlow、Caffe、Theano、Torch、CNTK,這裡記錄作為入門級的菜鳥如何配置Caffe - -計算機視覺庫。  
【Android原始碼篇】ubuntu上編譯I.MX6Q原始碼
參考文件: 一、Android刷機的元件含義 Android 啟動流程: 當你的Android手機啟動時首先會啟動RADIO,然後是SPL。 此時SPL 會根據你的按鍵,確定進入哪個模式( 例如Recovery,Fastboot等等), 如果沒有按其他
在Ubuntu上編譯libusb
下載libusb原始碼,進入目錄,shell下依次執行下列命令。 1. 執行:./configure 提示:configure: error: “udev support requested but l
Ubuntu上配置caffe+SSD及demo演示(附帶問題彙總)
實驗目的: 不得不說,現在深度學習真的是火,去年年底博主在做人臉識別這個應用的時候,選擇的是faster rcnn,還沒捂熱乎,現在又再看SSD的東西了。SSD和faster rcnn都是目前比較經典的基於caffe深度學習架構的一種方法,是目前比較先進的目標檢測方法,還有
Ubuntu上用caffe的SSD方法訓練umdfaces資料集
實驗目的 繼前一段時間用SSD訓練過VOC資料集以後,這一次使用SSD+K80伺服器來訓練自己的人臉識別應用,選擇的資料集還是之前下載的umdfaces,總共36w張人臉影象。 實驗環境 訓練平臺:NVIDIA K80 預測平臺:NVIDIA TX1 框架
(3)HomeAssistant安裝--Ubuntu上安裝python3和pip
導航連結 HomeAssistant安裝--homeassistant介紹 HomeAssistant安裝--python3和pip HomeAssistant安裝--python3和pip分支 HomeAssistant安裝--homeassistant &n