ubuntu配置caffe的python接口pycaffe

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ubuntu配置caffe的python接口pycaffe相关的知识,希望对你有一定的参考价值。

参考网站:

http://blog.csdn.net/sanmao5/article/details/51923982 (主要参考)

https://github.com/BVLC/caffe/issues/782 (问题解决)

 

ubuntu配置caffe的python接口pycaffe

  1. 依赖

前提caffe已经正确编译。见Ubuntu配置caffe

  1. 库包
    1. sudo apt-get install python-pip
    2. sudo atp-get install python-dev python-numpy
    3. sudo apt-get install gfortran
    4.  
    5. sudo pip install –r python/requirements.txt
    6. sudo pip install pydot

      numpy scipy matplotlib sklearn skimage h5py protobuf leveldb networkx nose pandas gflags Cython ipython gfortran

  2. 路径
    1. vi ~/.bashrc

export PYTHONPATH=/usr/caffe/python:$PYTHONPATH

export PYTHONPATH=/usr/caffe/python/caffe:$PYTHONPATH//千万不要加这个

  1. source ~/.bashrc
  1. 编译
    1. cd caffe
    2. make pycaffe
  2. 问题与解决

问题:

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

File "/Users//anaconda/lib/python2.7/site-packages/numpy/__init__.py", line 153, in <module>

from . import add_newdocs

File "/Users//anaconda/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>

from numpy.lib import add_newdoc

File "/Users//anaconda/lib/python2.7/site-packages/numpy/lib/__init__.py", line 22, in <module>

from .npyio import *

File "/Users//anaconda/lib/python2.7/site-packages/numpy/lib/npyio.py", line 4, in <module>

from . import format

File "/Users//anaconda/lib/python2.7/site-packages/numpy/lib/format.py", line 141, in <module>

import io

File "io.py", line 2, in <module>

import skimage.io

File "/Users//anaconda/lib/python2.7/site-packages/skimage/__init__.py", line 171, in <module>

from .util.dtype import *

File "/Users//anaconda/lib/python2.7/site-packages/skimage/util/__init__.py", line 1, in <module>

from .dtype import (img_as_float, img_as_int, img_as_uint, img_as_ubyte,

File "/Users//anaconda/lib/python2.7/site-packages/skimage/util/dtype.py", line 8, in <module>

dtype_range = {np.bool_: (False, True),

AttributeError: ‘module‘ object has no attribute ‘bool_

解决:

https://github.com/BVLC/caffe/issues/782 (问题解决)

SnShine

Firstly, you need to have _caffe.so in caffe/python/caffe. If not, run ‘make pycaffe‘ in caffe source folder.

Secondly, you need to add only caffe/python to $PYTHONPATH but not caffe/python/caffe as mentioned in documentation. I don‘t know why adding caffe/python/caffe causes the error, though.

seanbell

@deartonym you should add $CAFFE_ROOT/python to your $PYTHONPATH, not $CAFFE_ROOT/python/caffe.

If you add "$CAFFE_ROOT/python/caffe", then you won‘t be able to do "import caffe".

Yangqing has posted:

under the folder of caffe-master/python/caffe, where _caffe.so lies, there is an io.py, which would be wrongly used by numpy.

developfeng

If you succeeded "make pycaffe" without error and cannot solve the " AttributeError: ‘module‘ object has no attribute ‘bool_‘ " problem after you set PYTHONPATH, you‘d better check if you set too much different PATHONPATH via "echo $PYTHONPATH", if have more than one path, you can logout and log in, then add "expoet PYTHONPATH=$PYTHONPATH:/home/develop/caffe/python", then have a try!

以上是关于ubuntu配置caffe的python接口pycaffe的主要内容,如果未能解决你的问题,请参考以下文章

ubuntu14.04安装caffe+python接口

ubuntu下 编译Caffe的Matlab接口

CAFFE:Ubuntu 下安装jupyter notebook

FCN小小实战

ubuntu16.04 安装配置matlab ,python ,cuda8.0,cudnn,opencv3.1的caffe环境

Mac OSX (EI Capitan)搭建Caffe环境并配置python接口