caffe-ssd 安装+填坑

caffe-ssd 安装+填坑+SSD的focal_loss实现(Ubuntu系统)

安装:
1、安装依赖库

sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install --no-install-recommends libboost-all-dev
sudo apt-get install libatlas-base-dev libopenblas-dev
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev

2、下载源码:https://github.com/weiliu89/caffe/tree/ssd

3、修改config文件:

修改各种路径为

# Whatever else you find you need goes here.
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/cuda-10.0/include/thrust/system/cuda/detail /usr/include/thrust/system/cuda/detail /usr/local/include /usr/include/hdf5/serial/
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial /usr/local/cuda-10.0/include/thrust/system/cuda/detail/

修改计算力为:

CUDA_ARCH := -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 

编译最基础的caffe,在 Makefile.config 中将以下路径添加:(设置临时环境变量)

export LD_LIBRARY_PATH=xxxxx/protobuf_3/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=xxxxx/protobuf_3/bin:$LD_LIBRARY_PATH
export PATH=xxxxx/protobuf_3/bin:$PATH

4、make all -j16
5、测试:

make test
make runtest

6、编译python接口:

make pycaffe

7、测试pycaffe:

python 
import caffe

ImportError: No module named skimage.io

pip install scikit-image

再次:

python
import caffe

不报错,则安装成功

填坑

1、

make pycaffe
CXX/LD -o python/caffe/_caffe.so python/caffe/_caffe.cpp
python/caffe/_caffe.cpp:10:10: fatal error: numpy/arrayobject.h: No such file or directory
 #include 
          ^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Makefile:501: recipe for target 'python/caffe/_caffe.so' failed
make: *** [python/caffe/_caffe.so] Error 1

报错原因:numpy路径不对

解决办法:打开Makefile.connfig文件,在PYTHONINCLUDE环境下面输入正确的地址

查找地址:

whereis Python

查找numpy位置:

>>>Python
>>>import numpy as np
>>>np.__file__

2、

Check failed: status == CUDNN_STATUS_SUCCESS (4 vs. 0)  CUDNN_STATUS_INTERNAL_ERROR

解决方法:在命令前加sudo
3、

Check failed: num_priors_ * num_classes_ == bottom[1]->channels() (132174 vs. 99406) Number of priors must match number of confidence predictions.

由置信引起,一般是由分类类别没有改好引起的,其中括号里的数字无所谓,和自己的数据有关

4、

Check failed: num_priors_ * num_loc_classes_ * 4 == bottom[0]->channels() (264348 vs. 88116) Number of priors must match number of location predictions.

由位置引起

5、
编译时出现“XXXX没有定义”,报错类似于:

/usr/local/cuda/include/cuda_runtime_api.h:5864:102: error: use of enum ‘cudaMemRangeAttribute’ without previous declaration0
 extern __host__ cudaError_t CUDARTAPI cudaMemRangeGetAttributes(void **data, size_t *dataSizes, enum cudaMemRangeAttribute *attributes, size_t numAttributes, const void *devPtr, size_t count);
                                                                                                     ^
Makefile:200: recipe for target 'mnistCUDNN.o' failed
make: *** [mnistCUDNN.o] Error 1

解决方法:
将文件/usr/include/cudnn.h 中的

#include "driver_types.h" 改为:#include 

6、

ImportError: No module named caffe.proto

解决方法:
方法1:

1.打开 ~/caffe-ssd/scripts/create_annoset.py 文件。 
2.在import sys和from caffe.proto import caffe_pb2这两段代码中间插入
sys.path.insert(0,/home/xxx/caffe_ssd/ python’)这句代码,
xxx为你们自己的用户名。

方法2:
在终端执行:

export PYTHONPATH=xxxx/caffe-ssd/python:$PYTHONPATH

7、

按本地方式在服务器端训练网络会报错:注意不是编译caffe时报的

Check failed: status == CUDNN_STATUS_SUCCESS (3 vs. 0)
CUDNN_STATUS_BAD_PARAM

解决方法:

在train.prototxt的每个卷积层convolution_param中添加engine: CAFFE

8、

LD -o .build_release/lib/libcaffe.so.1.0.0
/usr/bin/ld: 找不到 -lopencv_imgcodecs
collect2: error: ld returned 1 exit status
Makefile:572: recipe for target '.build_release/lib/libcaffe.so.1.0.0' failed
make: *** [.build_release/lib/libcaffe.so.1.0.0] Error 1

原因:系统默认路径下是opencv2的版本,它不包含libopencv_imgcodecs.so库,所以要修改到自己的opencv3的路径下

解决方法:

在Makefile.config 中的# Whatever else you find you need goes here.一行的LIBRARY_DIRS :=的最后空一格然后添加自己的opencv3的库的路径,如下:

LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial /data_1/opencv/opencv3.2.0/lib 

9、

python
import caffe

报错:

ImportError: No module named skimage.io

解决方法:

pip install scikit-image

报错:

ImportError: No module named google.protobuf.internal

解决方法:

sudo pip install protobuf

10、

training error: Data layer prefetch queue empty #863

添加代码段:

if(bbox_width>=1.0){
bbox_width=1.0;
}
if(bbox_height>=1.0){
bbox_height=1.0;
}

到src/caffe/util/sampler.cpp
如下:

src/caffe/util/sampler.cpp
float bbox_width = scale * sqrt(aspect_ratio);
float bbox_height = scale / sqrt(aspect_ratio);
if(bbox_width>=1.0){
bbox_width=1.0;
}
if(bbox_height>=1.0){
bbox_height=1.0;
}
// Figure out top left coordinates.
float w_off, h_off;

11、
解决路径指定问题

sudo apt-get update
sudo gedit ~/.bashrc
source ~/.bashrc

12、

In file included from ./include/caffe/util/device_alternate.hpp:40:0,
                 from ./include/caffe/common.hpp:19,
                 from ./include/caffe/blob.hpp:8,
                 from ./include/caffe/filler.hpp:10,
                 from src/caffe/layers/embed_layer.cpp:3:
./include/caffe/util/cudnn.hpp:8:10: fatal error: caffe/proto/caffe.pb.h: 没有那个文件或目录 #include "caffe/proto/caffe.pb.h"

解决方法:用protoc从caffe/src/caffe/proto/caffe.proto生成caffe.pb.h和caffe.pb.cc

cd 到 ./src/caffe/proto 文件夹后执行语句:

protoc caffe.proto --cpp_out=./ 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值