caffe python接口编译

1、如果有需要用opnecv的话可以进行这一步。
在github上有大神已经将脚本写好地址:opencv脚本下载链接直接copy就好,安装起来麻烦。

解压:unzip /home/yyy/下载/Install-OpenCV-master.zip (yyy:)
进入解压文件夹执行脚本:sudo ./opencv2_4_9.shsudo bash opencv2_4_9.sh

2、下载caffe

下载地址:https://github.com/BVLC/caffe 解压

进入caffe的目录,修改 配置文件Makefile.config.example 的文件名改为Mikefile.config

可以直接改,也可以用命令改cp Mkefile.config.example Makefile.config
3、修改配置文件


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

# uncomment to disable IO dependencies and corresponding data layers
 USE_OPENCV := 1
# Uncomment if you're using OpenCV 3
 OPENCV_VERSION := 2.4.9
# 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

我这个之编译了pycaffe,如果有需要编译matlab版本的可以直接修改matlab dir的路径:MATLAB_DIR :=这个maltab 的安装路径复制进去,添加路径到bin即可。
3,安装caffe依赖包

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 libgflags-dev libgoogle-glog-dev liblmdb-dev
sudo apt-get install libatlas-base-dev

4、先直接编译caffe

make all -j4
make test -j4
make runtest -j4

5、编译python接口
首先安装anaconda2,使用的是版本python2.7,可去官网直接下载。在安装即可。
编译python接口。由于已经修改过Mikefile的配置文件,直接进入caffe目录直接编译:make pycaffe matlab同理,由于ubuntu在使用gcc版本较高,编译使用matlab时编译不了,在安装matlab时需要进行gcc降级。
6、import caffe
首先打开anaconda自带的spyder,发现我的版本还是ubuntu自带的python,所以将anaconda的环境变量加入,打开gedit ~/.bashrc,在最后一行加入anaconda的环境:export PATH="/home/yyy/anaconda2/bin:$PATH"加入即可。更新环境变量source ~/.bashrc
进入caffe/python的目录下导入,如果没在python目录下出现如下结果

>>> import caffe
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named caffe  

进入caffe的python目录

cd /home/cross_li/caffe-master/python/

又出现如下错误:ImportError: No module named google.protobuf.internal
那就安装protobuf:conda install protobuf

如果报这个错误请执行Error: Missing write permissions in: /home/cross_li/anaconda2

sudo chmod 777 -R anaconda2
yyy:~$ conda install protobuf

最后没有报错即可。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值