第一步:

 git clone https://github.com/weiliu89/caffe.git
 cd caffe
 git checkout ssd

git下载可能速度慢,可自行查找解决方案。例:

1、将下列内容加入 /etc/hosts文件中

151.101.113.194 http://global-ssl.fastly.Net
192.30.253.112 http://github.com

2、刷新DNS缓存 

sudo /etc/init.d/networking restart

第二步:

进入caffe目录下

cd  caffe/
cp  Makefile.config.example  Makefile.config

Makefile.config的修改如下:

# 
# All modification made by Intel Corporation: © 2016 Intel Corporation
# 
# All contributions by the University of California:
# Copyright (c) 2014, 2015, The Regents of the University of California (Regents)
# All rights reserved.
# 
# All other contributions:
# Copyright (c) 2014, 2015, the respective contributors
# All rights reserved.
# For the list of contributors go to https://github.com/BVLC/caffe/blob/master/CONTRIBUTORS.md
# 
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 
#     * Redistributions of source code must retain the above copyright notice,
#       this list of conditions and the following disclaimer.
#     * Redistributions in binary form must reproduce the above copyright
#       notice, this list of conditions and the following disclaimer in the
#       documentation and/or other materials provided with the distribution.
#     * Neither the name of Intel Corporation nor the names of its contributors
#       may be used to endorse or promote products derived from this software
#       without specific prior written permission.
# 
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
## Refer to http://caffe.berkeleyvision.org/installation.html
# Contributions simplifying and improving our build system are welcome!

# cuDNN acceleration switch (uncomment to build with cuDNN).
# USE_CUDNN := 1

# CPU-only switch (uncomment to build without GPU support).
CPU_ONLY := 1

# USE_MKL2017_AS_DEFAULT_ENGINE flag is OBSOLETE
# Put this at the top your train_val.protoxt or solver.prototxt file:
# engine: "MKL2017" 
# or use this option with caffe tool:
# -engine "MKL2017"

# USE_MKLDNN_AS_DEFAULT_ENGINE flag is OBSOLETE
# Put this at the top your train_val.protoxt or solver.prototxt file:
# engine: "MKLDNN" 
# or use this option with caffe tool:
# -engine "MKLDNN"

# uncomment to disable IO dependencies and corresponding data layers
USE_OPENCV := 1
USE_LEVELDB := 1
USE_LMDB := 1

# uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary)
#	You should not set this flag if you will be reading LMDBs with any
#	possibility of simultaneous read and write
# ALLOW_LMDB_NOLOCK := 1

# Uncomment if you're using OpenCV 3
# OPENCV_VERSION := 3

# To customize your choice of compiler, uncomment and set the following.
# N.B. the default for Linux is g++ and the default for OSX is clang++
# CUSTOM_CXX := g++

# If you use Intel compiler define a path to newer boost if not used
# already. 
# BOOST_ROOT := 

# Intel(r) Machine Learning Scaling Library (uncomment to build
# with MLSL for multi-node training)
# USE_MLSL :=1

# CUDA directory contains bin/ and lib/ directories that we need.
CUDA_DIR := /usr/local/cuda
# On Ubuntu 14.04, if cuda tools are installed via
# "sudo apt-get install nvidia-cuda-toolkit" then use this instead:
# CUDA_DIR := /usr

# CUDA architecture setting: going with all of them.
# For CUDA < 6.0, comment the *_50 lines for compatibility.
#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_50,code=compute_50

# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
BLAS := mkl
# Custom (MKL/ATLAS/OpenBLAS) include and lib directories.
# Leave commented to accept the defaults for your choice of BLAS
# (which should work)!

BLAS_DIR := $(MKLROOT)/include
BLAS_LIB := $(MKLROOT)/lib/intel64

# BLAS_INCLUDE := /path/to/your/blas
# BLAS_LIB := /path/to/your/blas

# Homebrew puts openblas in a directory that is not on the standard search path
# BLAS_INCLUDE := $(shell brew --prefix openblas)/include
# BLAS_LIB := $(shell brew --prefix openblas)/lib

# This is required only if you will compile the matlab interface.
# MATLAB directory should contain the mex binary in /bin.
# MATLAB_DIR := /usr/local
# MATLAB_DIR := /Applications/MATLAB_R2012b.app

# NOTE: this is required only if you will compile the python interface.
# We need to be able to find Python.h and numpy/arrayobject.h.
PYTHON_INCLUDE := /usr/include/python2.7 \
		/usr/lib/python2.7/dist-packages/numpy/core/include
# Anaconda Python distribution is quite popular. Include path:
# Verify anaconda location, sometimes it's in root.
# ANACONDA_HOME := $(HOME)/anaconda
# PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
		# $(ANACONDA_HOME)/include/python2.7 \
		# $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include \

# Uncomment to use Python 3 (default is Python 2)
# PYTHON_LIBRARIES := boost_python3 python3.5m
# PYTHON_INCLUDE := /usr/include/python3.5m \
#                 /usr/lib/python3.5/dist-packages/numpy/core/include

# We need to be able to find libpythonX.X.so or .dylib.
PYTHON_LIB := /usr/lib
# PYTHON_LIB := $(ANACONDA_HOME)/lib

# Homebrew installs numpy in a non standard path (keg only)
# PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/include
# PYTHON_LIB += $(shell brew --prefix numpy)/lib

# Uncomment to support layers written in Python (will link against Python libs)
WITH_PYTHON_LAYER := 1

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

# If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies
# INCLUDE_DIRS += $(shell brew --prefix)/include
# LIBRARY_DIRS += $(shell brew --prefix)/lib

# Uncomment to use `pkg-config` to specify OpenCV library paths.
# (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.)
# USE_PKG_CONFIG := 1

# N.B. both build and distribute dirs are cleared on `make clean`
BUILD_DIR := build
DISTRIBUTE_DIR := distribute

# Uncomment to enable training performance monitoring
# PERFORMANCE_MONITORING := 1

# Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171
# DEBUG := 1

# Uncomment to disable OpenMP support.
# USE_OPENMP := 0

# The ID of the GPU that 'make runtest' will use to run unit tests.
#TEST_GPUID := 0

# enable pretty build (comment to see full commands)
Q ?= @

第三步:

编译caffe:(重新编译时 要先 make clean)

make all  -j6  //-j16根据本机的处理器配置,16是16核处理器的意思
//可使用如下命令查看: cat /proc/cpuinfo |grep "cores"|uniq
make pycaffe -j6
make test -j6
make runtest -j6(这一步不是必须的)

如果出现:

[  FAILED  ] AdamSolverTest/0.TestSnapshotShare, where TypeParam = caffe::CPUDevice<float>

如果使用了Intel MKL作为BLAS,可能是Intel MKL的浮点数计算功能没有设置正确。使用如下命令:

export MKL_CBWR=AUTO

然后重新make runtest

第四步:

将图片转化为LMDB文件;将前面生成好的VOC数据集在data文件夹下(即/home/xxx/caffe-ssd/data)新建文件夹,命名为widerface

将VOC0712中的文件拷贝过来进行修改

create_list:

#!/bin/bash

root_dir=/home/caffe/caffe/data/widerface/     //修改
sub_dir=ImageSets/Main
bash_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
for dataset in trainval test
do
  dst_file=$bash_dir/$dataset.txt
  if [ -f $dst_file ]
  then
    rm -f $dst_file
  fi
  for name in wider_face  //修改
  do
    if [[ $dataset == "test" && $name == "VOC2012" ]]
    then
。。。。。。。
余下部分省略

运行脚本:

此时可能出现 error while loading shared libraries: libmkl_rt.so: cannot open shared object file: No such file or directory。

解决方法如下:

locate  libmkl_rt.so 找到该文件所在的目录

# cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
# echo "/opt/intel/mkl/lib/intel64/" >> /etc/ld.so.conf
# ldconfig

生成成功后如下:

caffe+SSD+Ubuntu14.04+CPU的配置及运行

生成如下三个.txt文件

caffe+SSD+Ubuntu14.04+CPU的配置及运行

create_data.sh 的修改:

data_root_dir="/home/caffe/caffe/data/widerface/"
dataset_name="widerface"

运行脚本:

此时如果出现no module named caffe或者是no module named caffe-proto,则:

scripts下的create_annoset.py文件没有添加pycaffe路径

添加如下:

import sys
sys.path.append(' your caffe path/python') #your caffe path就是你caffe-ssd的安装路径

 

相关文章: