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!

时间: 2024-10-13 21:52:45

ubuntu配置caffe的python接口pycaffe的相关文章

caffe的python接口学习(7):绘制loss和accuracy曲线

使用python接口来运行caffe程序,主要的原因是python非常容易可视化.所以不推荐大家在命令行下面运行python程序.如果非要在命令行下面运行,还不如直接用 c++算了. 推荐使用jupyter notebook,spyder等工具来运行python代码,这样才和它的可视化完美结合起来. 因为我是用anaconda来安装一系列python第三方库的,所以我使用的是spyder,与matlab界面类似的一款编辑器,在运行过程中,可以查看各变量的值,便于理解,如下图: 只要安装了anac

caffe的python接口学习(4)mnist实例手写数字识别

以下主要是摘抄denny博文的内容,更多内容大家去看原作者吧 一 数据准备 准备训练集和测试集图片的列表清单; 二 导入caffe库,设定文件路径 # -*- coding: utf-8 -*- import caffe from caffe import layers as L,params as P,proto,to_proto #设定文件的保存路径 root='/home/xxx/' #根目录 train_list=root+'mnist/train/train.txt' #训练图片列表

caffe的python接口学习(8):caffemodel中的参数及特征的抽取

如果用公式  y=f(wx+b) 来表示整个运算过程的话,那么w和b就是我们需要训练的东西,w称为权值,在cnn中也可以叫做卷积核(filter),b是偏置项.f是激活函数,有sigmoid.relu等.x就是输入的数据. 数据训练完成后,保存的caffemodel里面,实际上就是各层的w和b值. 我们运行代码: deploy=root + 'mnist/deploy.prototxt' #deploy文件 caffe_model=root + 'mnist/lenet_iter_9380.ca

caffe使用 python接口

使用caffe训练好的模型进行分类: http://blog.csdn.net/thy_2014/article/details/51648730 提取caffe前馈的中间结果+逐层可视化: http://blog.csdn.net/thy_2014/article/details/51659300

caffe的python接口学习(5):生成deploy文件

如果要把训练好的模型拿来测试新的图片,那必须得要一个deploy.prototxt文件,这个文件实际上和test.prototxt文件差不多,只是头尾不相同而也.deploy文件没有第一层数据输入层,也没有最后的Accuracy层,但最后多了一个Softmax概率层. 这里我们采用代码的方式来自动生成该文件,以mnist为例. deploy.py # -*- coding: utf-8 -*- from caffe import layers as L,params as P,to_proto

caffe的python接口学习(6):用训练好的模型(caffemodel)来分类新的图片

经过前面两篇博文的学习,我们已经训练好了一个caffemodel模型,并生成了一个deploy.prototxt文件,现在我们就利用这两个文件来对一个新的图片进行分类预测. 我们从mnist数据集的test集中随便找一张图片,用来进行实验. #coding=utf-8 import caffe import numpy as np root='/home/xxx/' #根目录 deploy=root + 'mnist/deploy.prototxt' #deploy文件 caffe_model=

Ubuntu配置vim支持Python编程

如未安装vim,使用下面命令安装: sudo apt-get install vim 在用户目录下创建.vim目录,其下创建bundle目录: mkdir .vim\bundle 安装Bundle/Vundle: git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle 创建或编辑用户目录下的.vimrc文件,添加如下内容: set nocompatible set rtp+=~/.vim/bundle/vundle/

windows配置caffe及matlab接口编译和调用(cpu和gpu)

环境:windows 7+matlab2016a+vs2013 caffe下载地址:https://github.com/BVLC/caffe/tree/windows 1 进入caffe-windows的windows文件夹,Copy .\windows\CommonSettings.props.example to .\windows\CommonSettings.props 2 打开caffe工程,编辑CommonSettings.props文件,以下是cpu版本设置 <CpuOnlyBu

caffe的python接口学习(3)训练模型training

如果不进行可视化,只想得到一个最终的训练model, 那么代码非常简单,如下 : import caffe caffe.set_device(0) caffe.set_mode_gpu() solver = caffe.SGDSolver('/home/xxx/data/solver.prototxt') solver.solve() 原文地址:https://www.cnblogs.com/niulang/p/8984829.html