caffe make


原文链接: caffe make

[caffe 运行错误]ImportError: No module named caffe

如果报错,先确认路径一定是路径的问题,可以通过cd尝试是否正确。踩坑坑坑多次。

  1. make pycaffe ## 生成pycaffe库
  2. make distribute ## 生成发布的caffe程序
    /etc/profile

export PYTHONPATH="/home/ubuntu/caffe/models/weiliu89/distribute/python:$PYTHONPATH"
export LD_LIBRARY_PATH="/home/ubuntu/caffe/models/weiliu89/distribute/lib:$LD_LIBRARY_PATH"

【caffe 运行错误】ImportError: dynamic module does not define module export function (PyInit__caffe)

切记:
caffe 编译最大的坑就是 Makefile.config 中指定的版本python2.7和系统版本不一致
由于系统中安装了annaconda 等环境还有 python2 和python3并存等环境导致上述问题

因此 一定要检查系统中使用python 和 Makefile.config 中配置一致
whereis python

检查项

  1. 检查python --version 和 Makefile.config 中python是否一致? ==> update-alternatives --config python
  2. 检查 gcc -v
  3. 检查 nvcc --version
  4. 检查 sudo find /usr/lib -name "*libboost*" 1.65


pip uninstall protobuf

安装Pycaffe - greenchina1992的专栏 - CSDN博客
安装caffe碰到的坑 - 浩瀚之水的专栏 - CSDN博客
Ubuntu18.04 Caffe 安装步骤记录(超详尽) - 念去去的博客 - CSDN博客

sudo apt-get install protobuf-compiler libprotobuf-dev 

sudo apt-get install libleveldb-dev libsnappy-dev  libhdf5-serial-dev 
 
sudo apt-get install --no-install-recommends libboost-all-dev


sudo apt-get install libopenblas-dev liblapack-dev libatlas-base-dev
 
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev

sudo apt-get install git cmake build-essential

sudo apt-get install libopencv-dev

sudo apt install libboost-dev libboost-filesystem-dev libboost-thread-dev libboost-python-dev

有一定几率安装失败而导致后续步骤出现问题,所以要确保以上依赖包都已安装成功,验证方法就是重新运行安装命令,如验证 git cmake build-essential是否安装成功共则再次运行以下命令:
sudo apt-get install git cmake build-essential

  1. 源码 安装protobuf 3.9 和 opencv3.x 解决编译依赖导致的错误
  2. 增加 hdf5 支持

Makefile.config

# Whatever else you find you need goes here.
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib

INCLUDE_DIRS += /usr/include/hdf5/serial/
LIBRARY_DIRS += /usr/lib/x86_64-linux-gnu/hdf5/serial
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial

  1. 切记: 很多错误是由复制多余的空个导致的配置文件错误,肉眼是看不出来的
    比如下面的错误 是由 LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial 复制的时候有人眼看不见的字符
    .build_release/lib/libcaffe.so: undefined reference to cv::VideoCapture::set(int, double)' .build_release/lib/libcaffe.so: undefined reference tocv::VideoCapture::operator>>(cv::Mat&)'
    .build_release/lib/libcaffe.so: undefined reference to `cv::VideoCapture::isOpened() const'

修改 python 环境

### Makefile.config
# 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)/anaconda2
 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

protobuf /usr/include

【caffe编译】 fatal error: google/protobuf/port_def.inc:

原因: protobuf 版本不兼容 经过多次尝试采用 protobuf-3.9.1 问题解决

源码安装: protobuf

aria2c -c https://github.com/protocolbuffers/protobuf/releases/download/v3.9.1/protobuf-all-3.9.1.tar.gz

tar zxvf protobuf-all-3.9.1.tar.gz

cd protobuf-3.9.1/
./configure –prefix=/usr/local/protobuf(你的安装路径)
make
make check
make install
protoc –version

添加环境变量:vim ~/.bashrc
export PATH=/usr/local/protobuf/bin/:$PATH
export PKG_CONFIG_PATH=/usr/local/protobuf/lib/pkgconfig/

export LD_LIBRARY_PATH=/usr/local/protobuf/lib:$LD_LIBRARY_PATH

测试:

protoc –verison(查看版本)

which protoc(查看路径)

【caffe编译】 fatal error: hdf5.h: 没有那个文件或目录

src/caffe/layers/hdf5_output_layer.cpp:3:18: fatal error: hdf5.h: 没有那个文件或目录
查找文件

locate hdf5.h

修改Makefile.config文件,在下面的语句后面增加红色部分
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib

INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/
INCLUDE_DIRS += /usr/include/hdf5/serial/
LIBRARY_DIRS += /usr/lib/x86_64-linux-gnu/hdf5/serial

Makefile中修改为

LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs

【caffe编译】 Unsupported gpu architecture 'compute_20'

NVCC src/caffe/layers/reduction_layer.cu
nvcc fatal   : Unsupported gpu architecture 'compute_20'
Makefile:588: recipe for target '.build_release/cuda/src/caffe/layers/reduction_layer.o' failed
make: *** [.build_release/cuda/src/caffe/layers/reduction_layer.o] Error 1


# CUDA architecture setting: going with all of them.
# For CUDA < 6.0, comment the *_50 through *_61 lines for compatibility.
# For CUDA < 8.0, comment the *_60 and *_61 lines for compatibility.
# For CUDA >= 9.0, comment the *_20 and *_21 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_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时,遇见boost函数undefined reference to `boost::xxxxxx

修改makefile文件,将需要的boost::xxxxxx库,加到LIBRARIES后面

例如

.build_release/lib/libcaffe.so: undefined reference to boost::cpp_regex_traits<char>::toi(char const*&, char const*, int) const' .build_release/lib/libcaffe.so: undefined reference toboost::re_detail::get_default_error_string(boost::regex_constants::error_type)'
.build_release/lib/libcaffe.so: undefined reference to boost::re_detail::cpp_regex_traits_implementation<char>::transform(char const*, char const*) const' .build_release/lib/libcaffe.so: undefined reference toboost::re_detail::put_mem_block(void*)'
.build_release/lib/libcaffe.so: undefined reference to boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int)' .build_release/lib/libcaffe.so: undefined reference toboost::re_detail::raise_runtime_error(std::runtime_error const&)'

上面错误是 undefined reference没有将regex填入LIBRARIES 中

修改LIBRARIES ,将boost_regex加入进去

We will also explicitly add stdc++ to the link target.
LIBRARIES += boost_regex boost_atomic boost_thread stdc++

下载openc3.4.1数据包

https://github.com/opencv/opencv/releases

sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff5-dev libdc1394-22-dev # 处理图像所需的包
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev liblapacke-dev
sudo apt-get install libxvidcore-dev libx264-dev # 处理视频所需的包
sudo apt-get install libatlas-base-dev gfortran # 优化opencv功能

安装 bootstrap

  1. 设置编译器和所选库
    进如解压目录:

cd boost_1_68_0

运行bootstrap.sh脚本并设置相关参数.

./bootstrap.sh --with-libraries=all --with-toolset=gcc
–with-libraries:指编译哪些boost库,all的话就是全部编译,只想编译部分库的话就把库的名称写上,之间用 , 号分隔即可,这里建议选择all
–with-toolset:指编译时使用哪种编译器,Ubuntu下使用gcc即可,如果系统中安装了多个版本的gcc,在这里可以指定gcc的版本,比如–with-toolset=gcc-5.5
命令执行完成后看到显示如下即为成功:
Building Boost.Build engine with toolset gcc... tools/build/src/engine/bin.linuxx86_64/b2
Detecting Python version... 2.6
Detecting Python root... /usr
Unicode/ICU support for Boost.Regex?... not found.
Generating Boost.Build configuration in project-config.jam...

Bootstrapping is done. To build, run:

./b2

  1. 编译
    在终端执行:

./b2 toolset=gcc

编译过程会持续好一会,可以喝杯茶~
编译成功会有以下提示:

...updated XXX targets... //XXX指一个数字

4.安装
在终端执行:

./b2 install
–prefix=/usr:用来指定boost的安装目录,不加此参数的话默认的头文件在/usr/local/include/boost目录下,库文件在/usr/local/lib/目录下。这里把安装目录指定为–prefix=/usr则boost会直接安装到系统头文件目录和库文件目录下,可以省略配置环境变量。
安装完成会有以下界面:

...updated XXXX targets... //XXX指一个数字

使安装的boost库立即生效.

ldconfig //更新系统的动态链接库

此时再回去执行以下步骤:

sudo make clean
sudo make all -j32 //这一步也许会出现其他错误,但是此错误解决

                  //如果出现其他错误,可以多make clean 和make all 几次,再不行可以查看其他解决方法。

caffe编译opencv和boost问题

https://dl.bintray.com/boostorg/release/1.71.0/source/boost_1_71_0.7z

ifeq ($(USE_OPENCV), 1)
    LIBRARIES += opencv_core opencv_highgui opencv_imgproc opencv_videoio opencv_imgcodecs boost_regex

加上opencv_videoio opencv_imgcodecs boost_regex

 # Make sure you grab the latest version
 

`aria2c -c https://github.com/protocolbuffers/protobuf/releases/download/v3.10.1/protoc-3.10.1-linux-x86_64.zip`
# Unzip
unzip protoc-3.10.1-linux-x86_64.zip -d protoc3

# Move protoc to /usr/local/bin/
sudo mv protoc3/bin/* /usr/local/bin/

# Move protoc3/include to /usr/local/include/
sudo mv protoc3/include/* /usr/local/include/

# Optional: change owner
sudo chown $USER /usr/local/bin/protoc
sudo chown -R $USER /usr/local/include/google

源码安装 protobuf

aria2c -c https://github.com/protocolbuffers/protobuf/releases/download/v3.9.1/protobuf-all-3.9.1.tar.gz

tar zxvf protobuf-all-3.9.1.tar.gz

cd protobuf-3.9.1/
`./configure –prefix=/usr/local/protobuf`(你的安装路径)
make
make check
make install
protoc –version

添加环境变量:vim ~/.bashrc
export PATH=/usr/local/protobuf/bin/:$PATH
export PKG_CONFIG_PATH=/usr/local/protobuf/lib/pkgconfig/

export LD_LIBRARY_PATH=/usr/local/protobuf/lib:$LD_LIBRARY_PATH

测试:

protoc –verison(查看版本)

which protoc(查看路径)
————————————————
版权声明:本文为CSDN博主「orzchenyuming」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_29936933/article/details/82107861

sudo ln -sf /usr/local/cuda-8.0/targets/x86_64-linux/lib/libcudnn.so.4.0.7 /usr/local/cuda-8.0/targets/x86_64-linux/lib/libcudnn.so.4
问题就解决了。。。。。。。。。。。。。
————————————————
版权声明:本文为CSDN博主「langb2014」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/langb2014/article/details/54376716

【caffe编译】fatal error: caffe/proto/caffe.pb.h: No such file or directory

#include "caffe/proto/caffe.pb.h"

一、可能是make太快造成的错误

make all -j 48  改为  make all -j16 试试

二、否则就是丢失问题了

解决方法2:用protoc从caffe/src/caffe/proto/caffe.proto生成caffe.pb.h和caffe.pb.cc
protoc --cpp_out=./caffe/include/caffe/ caffe.proto

#### 【caffe编译】caffe /usr/include/c++/7/cstdlib:75:15: fatal error: stdlib.h: No such file or dir

这种问题是新版的gcc 不要在把 /usr/include/ 加入到 INCLUDE_DIRS
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include -->> INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include

【caffe编译】在调用以前的python文件,运行会出以下问题:ImportError: No module named _caffe

在调用以前的python文件,运行会出以下问题:ImportError: No module named _caffe,然后我重新编译了下项目,比如我的项目路径为:~/flownet-caffe-master,在终端进入该目录,清理并重新编译项目:

make clean
make all -j4
make test -j4
下面这一步操作可选:

make runtest -j4
运行程序出现问题如下:

     

解决办法:

首先在项目路径下进入终端并执行:

sudo make pycaffe
注意:每次重新编译了caffe后都需要执行:sudo make pycaffe

然后添加项目caffe路径到环境变量:

方法一:(一次性)

直接在终端输入:(注意改为你的项目路径)

PYTHONPATH=/media/rongsong/3082E76F580983D6/ubnutu/Downloads/flownet2-master/python
这种方法是一次性的,关闭终端再打开时更改就失效了。

方法二:(永久)

在终端执行:

sudo gedit ~/.bashrc
在打开的文件后面添加:

export PYTHONPATH=/media/rongsong/3082E76F580983D6/ubnutu/Downloads/flownet2-master/python:$PYTHONPATH

使更改环境立刻生效,在终端输入:

source ~/.bashrc
如果在python代码里面出现ImportError: No module named cv2,尝试在终端下执行:

sudo apt-get install python-opencv
————————————————
版权声明:本文为CSDN博主「rs勿忘初心」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/sinat_33718563/article/details/80245576

Caffe中ImportError: dynamic module does not define module export function (PyInit__caffe)错误

出现这种错误,是因为python模块没有编译好。使用了Anaconda的3.6版本的caffe。

在/.bashrc中注释掉指定的anaconda的python路径的语句。

make clean后重新编译caffe即可。

caffe编译】 TypeError: new() got an unexpected keyword argument 'serialized_options'

 
serialized_pb=_b('\n(tensorboardX/proto/resource_handle.proto\x12\x0ctensorboardX\"r\n\x13ResourceHandleProto\x12\x0e\n\x06\x64\x65vice\x18\x01 \x01(\t\x12\x11\n\tcontainer\x18\x02 \x01(\t\x12\x0c\n\x04name\x18\x03 \x01(\t\x12\x11\n\thash_code\x18\x04 \x01(\x04\x12\x17\n\x0fmaybe_type_name\x18\x05 \x01(\tB/\n\x18org.tensorflow.frameworkB\x0eResourceHandleP\x01\xf8\x01\x01\x62\x06proto3')

解决办法:

pip uninstall protobuf
pip install -U protobuf
文章
————————————————
版权声明:本文为CSDN博主「左老师的小迷弟」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/imucaoyue/article/details/85127043

down下来后,进入目录

-rw-rw-r-- 1 ~ ~ 23986 8月 13 15:29 Makefile
-rw-rw-r-- 1 ~ ~ 4402 8月 10 17:05 Makefile.config.example

按照机器配置和环境的情况修改这两个文件,首先复制Makefile.config.example到Makefile.config

cp Makefile.config.example Makefile.config

在config文件里进行修改,如uncomment以下几项:

USE_CUDNN :=1,因为我们需要调用CUDNN运行caffe代码

OPENCV_VERSION :=3,因为机器上的opencv版本号是3.X

CUDA_ARCH := -gencode arch=compute_50,code=sm_50 \
             -gencode arch=compute_52,code=sm_52 \
             -gencode arch=compute_61,code=sm_61

CUDA_ARCH只保留这几项就行,这是和gpu的算力性能有关的项目,本机器用的是TITAN Xp,因此如果不把较小的注释掉就会报warning。

INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
1
加上hdf5的路径到include中。

这样Makefile的配置文件基本完成。下面对Makefile修改。

常见问题一般都是库找不到,因此主要关注这一段代码:

LIBRARIES += glog gflags protobuf boost_system boost_filesystem boost_regex m hdf5_serial_hl hdf5_serial

handle IO dependencies

USE_LEVELDB ?= 1
USE_LMDB ?= 1
USE_OPENCV ?= 1

ifeq ($(USE_LEVELDB), 1)

LIBRARIES += leveldb snappy

endif
ifeq ($(USE_LMDB), 1)

LIBRARIES += lmdb

endif
ifeq ($(USE_OPENCV), 1)

LIBRARIES += opencv_core opencv_highgui opencv_imgproc

ifeq ($(OPENCV_VERSION), 3)
    LIBRARIES += opencv_imgcodecs opencv_videoio
endif

endif
PYTHON_LIBRARIES ?= boost_python27 python2.7
WARNINGS := -Wall -Wno-sign-compare

第一行中的LIBRARIES += 。。。,如果报错某个库没有找到,可以加入到这一行,如boost_regex m hdf5_serial_hl hdf5_serial 都是添加上的。因为曾经报错boost_regex::XXX没有找到。

报错与解决
~/about-caffe/caffe-ssd$ make all
LD -o .build_release/lib/libcaffe.so.1.0.0-rc3
CXX/LD -o .build_release/tools/finetune_net.bin
CXX/LD -o .build_release/tools/convert_imageset.bin
.build_release/lib/libcaffe.so: undefined reference to boost::match_results<__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >::maybe_assign(boost::match_results<__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > > const&)' .build_release/lib/libcaffe.so: undefined reference toboost::re_detail::raise_runtime_error(std::runtime_error const&)'
.build_release/lib/libcaffe.so: undefined reference to boost::cpp_regex_traits<char>::toi(char const*&, char const*, int) const' .build_release/lib/libcaffe.so: undefined reference toboost::re_detail::put_mem_block(void)'
.build_release/lib/libcaffe.so: undefined reference to boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::construct_init(boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags)' .build_release/lib/libcaffe.so: undefined reference toboost::re_detail::get_mem_block()'
.build_release/lib/libcaffe.so: undefined reference to boost::re_detail::verify_options(unsigned int, boost::regex_constants::_match_flags)' .build_release/lib/libcaffe.so: undefined reference toboost::re_detail::get_default_error_string(boost::regex_constants::error_type)'
.build_release/lib/libcaffe.so: undefined reference to boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int)' .build_release/lib/libcaffe.so: undefined reference toboost::re_detail::cpp_regex_traits_implementation::transform(char const
, char const) const'
.build_release/lib/libcaffe.so: undefined reference to `boost::re_detail::cpp_regex_traits_implementation::transform_primary(char const
, char const*) const'
collect2: error: ld returned 1 exit status
Makefile:619: recipe for target '.build_release/tools/convert_imageset.bin' failed
make: *** [.build_release/tools/convert_imageset.bin] Error 1

问题类型:【undefined reference to `boost::re_detail::】

解决方案:看到一个说法是由于boost的版本过低,应该大于1.60,而本机的boost为1.58,所以手动下载一个boost进行安装,这里用的是1.68版本号的boost库,安装好之后问题解决。(安装boost参考本文:https://blog.csdn.net/this_capslock/article/details/47170313)

另一个问题是在make pycaffe时候,出现:

~/about-caffe/caffe-ssd$ make py
CXX/LD -o python/caffe/_caffe.so python/caffe/_caffe.cpp
/usr/bin/ld: cannot find -lboost_python
collect2: error: ld returned 1 exit status
Makefile:501: recipe for target 'python/caffe/_caffe.so' failed
make: *** [python/caffe/_caffe.so] Error 1

问题类型:【cannot find -lboost_python】,但是实际上在makefile中已经把boost_python 添加上了:

PYTHON_LIBRARIES ?= boost_python python2.7
1
这里的解决方案是吧上面一句改为:

PYTHON_LIBRARIES ?= boost_python27 python2.7
1
即将boost_python改为boost_python。

最后caffe和pycaffe都编译成功,运行ssd的python脚步,报错:

~/about-caffe/caffe-ssd$ python examples/ssd/ssd_pascal.py
Traceback (most recent call last):
File "examples/ssd/ssd_pascal.py", line 2, in

import caffe

ImportError: No module named caffe

错误类型:【No module named XXX】,这种情况有两种可能的原因,一是没有make pycaffe;另一种是没有把pycaffe的路径加入环境变量。这里我们make过了pycaffe,因此需要手动用加入pycaffe到环境变量。

caffe_root = '~/about-caffe/caffe-ssd/'
if caffe_root + 'python' not in sys.path:

sys.path.append(caffe_root + 'python')

sys.path.insert(0, caffe_root + 'python')

import caffe

这样就可以运行了。

接下来就是讲lmdb数据换成需要训练的自己的数据集,对ssd的caffe模型进行训练了~
————————————————
版权声明:本文为CSDN博主「江户川柯壮」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/edogawachia/article/details/81631991

## 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

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

# 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++

# 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 lines after *_35 for compatibility.
CUDA_ARCH := -gencode arch=compute_30,code=sm_30 \
             -gencode arch=compute_35,code=sm_35 \
             -gencode arch=compute_50,code=sm_50 \
             -gencode arch=compute_52,code=sm_52 \
             -gencode arch=compute_61,code=sm_61

# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
# BLAS := atlas
BLAS := open
# Custom (MKL/ATLAS/OpenBLAS) include and lib directories.
# Leave commented to accept the defaults for your choice of BLAS
# (which should work)!
# 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)/anaconda2
# 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
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
INCLUDE_DIRS += /usr/include/hdf5/serial/
LIBRARY_DIRS += /usr/lib/x86_64-linux-gnu/hdf5/serial
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl 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 for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171
# DEBUG := 1

# 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 ?= @
`