python调用caffe环境配置
背景是这样的,项目需要,必须将训练的模型通过C++进行调用,所以必须使用caffe或者mxnet,而caffe是用C++实现,所以有时候简单的加载一张图片然后再进行预测十分不方便
用caffe写prototxt比较容易,写solver也是很容易,但是如何根据传入的lmdb数据来predict每一个样本的类别,抑或如何得到样本预测为其他类的概率?这看起来是一个简单的问题,实际上,在pytorch中很容易实现,在caffe中可能需要修改c++代码,用起来不是很方便直观,所以能否通过python调用已经训练完的caffemodel以及deploy.prototxt来实现类别的预测?
这个时候需要在ubuntu上配置caffe,在ubuntu上配置caffe我主要参考了这篇博客,http://www.cnblogs.com/denny402/p/5088399.html
其实主要是有两部分,第一部分是修改Make.config文件,第二部分是解决so库找不到的问题
1.修改Makefile.config
关键点在于修改配置文件Make.config然后进行编译,我的Make.config文件如下,
## 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 := 0 # 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 *_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 := atlas # 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/R2014a # 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 LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib# 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 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 ?= @
主要是注意PYTHON_INCLUDE这一块怎么写,因为我系统中安装了anaconda2,所以我修改PYTHON_INCLUDE这一块为anaconda的路径
修改完成之后,进入caffe根目录,运行
1 sudo make pycaffe
,编译成功后,如果重复编译则会提示Nothing to be done for "pycaffe"
为了防止其他错误,还是编译一下test
1 sudo make test -j8 2 sudo make runtest -j8
2,解决so库找不到的问题
在编译的时候我倒是没有遇到什么问题,但是在进入到python环境中去的时候,我import caffe的时候倒是遇到了各种各样的问题,但是这种问题大致可以归结为一种类型,就是
error while loading shared libraries: libhdf5.so.10: cannot open shared object file: No such file or directory
就是找不到caffe想要的库文件,这个时候这个链接 (http://www.cnblogs.com/denny402/p/5088399.html给了一种解决的方法,原因大概是缺少动态链接库,这些库基本上我们之前都已经安装了,安装的路径是
/use/lib/x86_64-linux-gnu,ll libhdf*的话能够列出所有的libhdf相关的库文件,如下图
如上图所示,基本上系统里面有很多我们自己的库,只不过caffe依赖的版本与系统中的版本号不一致,这一点儿与caffe在包含cudnn库文件的时候类似,只不过caffe的cudnn貌似是在/usr/local/lib下
对已有的库创建软链接,能够解决找不到so库的问题,所以
1 cd /usr/lib/x86_64-linux-gnu 2 sudo ln -s libhdf5.so.7(我文件夹中的so库的版本号) libhdf5.so.10(caffe需要的版本号) 3 sudo ldconfig
可能还会遇到其他的有关羽so库找不到的问题,基本上都是按照这个套路来解决
然后import caffe就不会报错,保险起见,可以再编译运行一下test
转载于:https://www.cnblogs.com/yongjieShi/p/8053519.html
python调用caffe环境配置相关推荐
- python调用matlab环境配置、非常详细!!!_Python调用Matlab2014b引擎
用惯Python的你,是不是早已无法忍受matplotlib那丑陋无比的图以及蛋疼无比部署依赖? 当当当当,Matlab2014b的Python Engine API现已加入豪华午餐. 上次写了一篇文 ...
- (一)ubuntu下qtcreator +opencv下新建一个项目和调用caffe环境配置
一.用QtCreator创建一个项目 1.新建项目 2.选择项目类型 3.修改项目名和项目存放地址 4.接下来都选择下一步,直到项目生成成功 二.项目创建成功后,开始写opencv小程序 1. ...
- python调用matlab环境配置、非常详细!!!_[python][matlab]使用python调用matlab程序
问题引入 在做实验的时候,需要用到python和matlab工具来进行不同的处理,比如在run神经网络的时候,需要使用pytorch框架得到网络的各个参数,在得到参数后需要使用matlab进行聚类规划 ...
- Python selenium chrome 环境配置
Python selenium chrome 环境配置一.参考文章:1. 记录一下python easy_install和pip安装地址和方法http://heipark.iteye.com/blog ...
- Python灰帽子环境配置
关于Python灰帽子里面的python代码运行环境配置,需要安装python2.7.x,自行到http://www.python.org下载. 我配置好环境后,把用到的库和pydbg需要替换的文件, ...
- python安装及环境配置
Python--python安装及环境配置 Python安装 Windowns操作系统中安装Python 步骤一 下载安装包 从Python网站https://www.python.org/downl ...
- Python调用matlab及其配置方法
Python调用matlab及其配置方法 - 知乎 从 Python 调用 MATLAB 函数的三种方法_wx60c0d572c0d91的技术博客_51CTO博客
- c++调用cplex求解例子_c++调用CPLEX环境配置
详情见公 号mp.weixin.qq.com 很难想象没有求解软件的几十年前 那些杰(苦)出(逼)的运筹学博士 要花多少个日日夜夜亲自撸一遍所有代码 才能把结果跑出来 毕(个)业(人)难(能)度(力 ...
- 上手机器学习前,先来学习下Python相关的环境配置吧~
点击上方"AI派",选择"设为星标" 最新分享,第一时间送达! 作者:奔雷手,目前是名在校学生,当前主要在学习机器学习,也在做机器学习方面的助教,相对还是比较了 ...
- Winds系统下python的基本环境配置
python环境配置 0.Windows下python3.7.IPython.Jupyter基本环境安装配置程 Windows系统在任意文件夹下打开cmd命令快捷方法 1.安装 xgboost (Wi ...
最新文章
- Fork 一个仓库并同步
- Linxu 进程描述符task_struct
- PPT科研绘图之棱台
- 【HDU - 1069】Monkey and Banana (最长下降子序列 + 贪心,最长上升子序列类问题)
- Windows下Ionic Android开发环境搭建
- 在PhpStorm9中与Pi的xdebug进行调试
- LCD1602单片机(STC51/STM32)驱动程序详解
- 异方差检验 python_stata教程03-异方差的检验和处理
- windows无法开启网络发现问题解决办法(详细)
- TPshop商城环境搭建(一)
- 利用Python实现scissors-rock-paper-lizard-Spock小游戏
- 【Jupyter Notebook】slides演示小技巧
- 出门忘带身份证?那就试试这几款好用软件
- (转)WAVE PCM 声音文件格式
- 如何实现一个下载进度条/播放进度条
- 海天蚝油《挑战不可能》7岁神童”盲棋“对抗,展现惊人脑力
- 开源PLM软件Aras详解八 Aras之RelationshipTypes关系类详解
- 重症医学数据库MIMIC-IV简介
- 剑网三重置版服务器维护,《剑网三》重制版基础教程,让你从入门萌新步入大佬行列...
- CREO 用最简单的方法做个莫比乌斯带
热门文章
- 【渝粤教育】 广东开放大学 10331k2_行政管理学_21秋考试
- 【渝粤题库】陕西师范大学200621 英语词汇学 作业
- 中国计算机学会推荐国际学术期刊--数据库/数据挖掘/内容检索
- SpringMVC中ModelAndView对象与“视图解析器”
- [转]非模态对话框的特点与使用
- 网络操作系统第十、十一章习题
- php连接阿里云mysql
- HTML table 标签的 summary 属性
- 插值和空间分析(二)_变异函数分析(R语言)
- [深入Python]Alex Martelli的Borg类