Caffe研究实践一------环境搭建

TensorFlow对应的是TheanoTorch

Caffe专精于图像处理,Caffe方便,更快入门上手;

在通用的DL task上,Caffe不如Theano。

开发环境搭建:

一、没有GPU

[email protected]-virtual-machine:~$ lspci | grep -i nvidia
[email protected]-virtual-machine:~$ 

二、ubuntu版本

[email protected]:~$ uname -m && cat /etc/*release
x86_64
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=15.10
DISTRIB_CODENAME=wily
DISTRIB_DESCRIPTION="Ubuntu 15.10"
NAME="Ubuntu"
VERSION="15.10 (Wily Werewolf)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 15.10"
VERSION_ID="15.10"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
[email protected]:~$

三、gcc

[email protected]virtual-machine:~$ gcc --version
gcc.real (Ubuntu 5.2.1-22ubuntu2) 5.2.1 20151010
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[email protected]virtual-machine:~$

四、安装依赖库

[email protected]-virtual-machine:~$ sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
[sudo] password for learning:
Reading package lists... Done
Building dependency tree      

sudo apt-get install --no-install-recommends libboost-all-dev

sudo apt-get install libatlas-base-dev

五、安装python

六、安装Opencv

安装Opencv

http://blog.csdn.net/forest_world/article/details/51372703Ubuntu

七、安装依赖库

[email protected]:~$ sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev

[sudo] password for learning:

Reading package lists… Done

八、下载Caffe

[email protected]:~$ git clone git://github.com/BVLC/caffe.git
Cloning into ‘caffe‘...
remote: Counting objects: 34637, done.
Receiving objects: 100% (34637/34637), 47.81 MiB | 81.00 KiB/s, done.
remote: Total 34637 (delta 0), reused 0 (delta 0), pack-reused 34636
Resolving deltas: 100% (23287/23287), done.
Checking connectivity... done.

九、修改

Makefile 修改:

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

这一块代码不需要修改

修改处:

caffe/examples/cpp_classification/classification.cpp文件

十、编译

[email protected]:~/caffe$ cp Makefile.config.example Makefile.config

[email protected]:~/caffe$ ls
caffe.cloc       data      INSTALL.md               matlab     src
cmake            docker    LICENSE                  models     tools
CMakeLists.txt   docs      Makefile                 python
CONTRIBUTING.md  examples  Makefile.config          README.md
CONTRIBUTORS.md  include   Makefile.config.example  scripts
[email protected]:~/caffe$ 

[email protected]:~/caffe$ gedit Makefile.config

[email protected]:~/caffe$ make all

出现问题:

[email protected]:~/caffe$ make all
PROTOC src/caffe/proto/caffe.proto
CXX .build_release/src/caffe/proto/caffe.pb.cc
CXX src/caffe/data_transformer.cpp
CXX src/caffe/common.cpp
CXX src/caffe/internal_thread.cpp
CXX src/caffe/blob.cpp
CXX src/caffe/data_reader.cpp
CXX src/caffe/parallel.cpp
CXX src/caffe/util/hdf5.cpp
In file included from src/caffe/util/hdf5.cpp:1:0:
./include/caffe/util/hdf5.hpp:6:18: fatal error: hdf5.h: No such file or directory
compilation terminated.
Makefile:572: recipe for target ‘.build_release/src/caffe/util/hdf5.o‘ failed
make: *** [.build_release/src/caffe/util/hdf5.o] Error 1
[email protected]:~/caffe$

解决:

Makefile.config

INCLUDE_DIRS

/usr/include/hdf5/serial/

Makefile

LIBRARIES

hdf5_hl and hdf5 改为 hdf5_serial_hl ,hdf5_serial

出现问题:

LD -o .build_release/lib/libcaffe.so.1.0.0-rc3
CXX tools/finetune_net.cpp
CXX/LD -o .build_release/tools/finetune_net.bin
CXX tools/net_speed_benchmark.cpp
CXX/LD -o .build_release/tools/net_speed_benchmark.bin
CXX tools/compute_image_mean.cpp
CXX/LD -o .build_release/tools/compute_image_mean.bin
.build_release/lib/libcaffe.so: undefined reference to `cv::imread(cv::String const&, int)‘
.build_release/lib/libcaffe.so: undefined reference to `cv::imencode(cv::String const&, cv::_InputArray const&, std::vector<unsigned char, std::allocator<unsigned char> >&, std::vector<int, std::allocator<int> > const&)‘
.build_release/lib/libcaffe.so: undefined reference to `cv::imdecode(cv::_InputArray const&, int)‘
collect2: error: ld returned 1 exit status
Makefile:616: recipe for target ‘.build_release/tools/compute_image_mean.bin‘ failed
make: *** [.build_release/tools/compute_image_mean.bin] Error 1

解决方法:

Makefile

修改:

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

编译成功:

make test

make runtest

[----------] 2 tests from BatchReindexLayerTest/0, where TypeParam = caffe::CPUDevice<float>
[ RUN      ] BatchReindexLayerTest/0.TestForward
[       OK ] BatchReindexLayerTest/0.TestForward (0 ms)
[ RUN      ] BatchReindexLayerTest/0.TestGradient
[       OK ] BatchReindexLayerTest/0.TestGradient (373 ms)
[----------] 2 tests from BatchReindexLayerTest/0 (374 ms total)

[----------] Global test environment tear-down
[==========] 1058 tests from 146 test cases ran. (134225 ms total)
[  PASSED  ] 1058 tests.
[email protected]virtual-machine:~/caffe$

十一、配置pycaffe

sudo apt-get install python-numpy python-scipy python-matplotlib python-sklearn python-skimage python-h5py python-protobuf python-leveldb python-networkx python-nose python-pandas python-gflags Cython ipython

sudo apt-get install protobuf-c-compiler protobuf-compiler

[email protected]:~/caffe$ make pycaffe

learning@learning-virtual-machine:~/caffe$ make pycaffe
CXX/LD -o python/caffe/_caffe.so python/caffe/_caffe.cpp
touch python/caffe/proto/__init__.py
PROTOC (python) src/caffe/proto/caffe.proto
learning@learning-virtual-machine:~/caffe$

sudo gedit /etc/profile

末尾添加: export PYTHONPATH=/path/to/caffe/python:$PYTHONPATH

用完整路径

source /etc/profile

[email protected]:~/caffe$ python

Python 2.7.10 (default, Oct 14 2015, 16:09:02)

[GCC 5.2.1 20151010] on linux2

Type “help”, “copyright”, “credits” or “license” for more information.

.>>>

出现问题:

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

解决方法:

sudo gedit /etc/profile

export PYTHONPATH=$PYTHONPATH:/home/learning/caffe/python

source /etc/profile

补充:baidu解释

Python(英国发音:/?pa?θ?n/ 美国发音:/?pa?θɑ?n/), 是一种面向对象、解释型计算机程序设计语言,由Guido van Rossum于1989年发明,第一个公开发行版发行于1991年。

Python是纯粹的自由软件, 源代码和解释器CPython遵循 GPL(GNU General Public License)协议[1] 。

Python语法简洁清晰,特色之一是强制用空白符(white space)作为语句缩进。

Python具有丰富和强大的库。它常被昵称为胶水语言,能够把用其他语言制作的各种模块(尤其是C/C++)很轻松地联结在一起。常见的一种应用情形是,使用Python快速生成程序的原型(有时甚至是程序的最终界面),然后对其中[2] 有特别要求的部分,用更合适的语言改写,比如3D游戏中的图形渲染模块,性能要求特别高,就可以用C/C++重写,而后封装为Python可以调用的扩展类库。需要注意的是在您使用扩展类库时可能需要考虑平台问题,某些可能不提供跨平台的实现。

参考资料:Ubuntu14.04 安装Caffe

http://blog.csdn.net/u011762313/article/details/47262549

时间: 2024-11-07 15:05:19

Caffe研究实践一------环境搭建的相关文章

Ubuntu14.04+caffe+cuda7.5 环境搭建以及MNIST数据集的训练与测试

Ubuntu14.04+caffe+cuda 环境搭建以及MNIST数据集的训练与测试 一.ubuntu14.04的安装: ubuntu的安装是一件十分简单的事情,这里给出一个参考教程: http://jingyan.baidu.com/article/76a7e409bea83efc3b6e1507.html 二.cuda的安装: 1.首先下载nvidia cuda的仓库安装包(我的是ubuntu 14.04 64位,所以下载的是ubuntu14.04的安装包,如果你是32位的可以参看具体的地

faster-rcnn(testing): ubuntu14.04+caffe+cuda7.5+cudnn5.1.3+opencv3.0+matlabR2014a环境搭建记录

python版本的faster-rcnn见我的另一篇博客: py-faster-rcnn(running the demo): ubuntu14.04+caffe+cuda7.5+cudnn5.1.3+python2.7环境搭建记录 1. 首先需要配置编译caffe的环境,并降级gcc为4.7.见: ubuntu14.04下安装cudnn5.1.3,opencv3.0,编译caffe及matlab和python接口过程记录(不好意思,这也是我自己写的) 2. clone 源码: git clon

大数据学习实践总结(2)--环境搭建,JAVA引导,HADOOP搭建

PS:后续的文章会把我实践的内容分解成为一个个的小模块,方便大家的学习,交流.文未我也会附上相关的代码.一起加油!    学有三年的大数据原理,一直没有实践过.最近准备离职,正好把自己所学的大数据内容全部实践一下,也不至于只会纯理论.面对实践,首先要有空杯心态,倒空自己之后,才能学到更多,加油!也希望大家多关注,以后会更多注重实践跟原理的结合. 环境搭建 对于大数据,重点在于Hadoop的底层架构.虽说现在spark架构用的还是比较多.但hadoop还是基础.还有就是为什么要以Linux为基础,

Hadoop 实践(一) 环境搭建

大数据定义是:大量的非结构话的数据.量要大,要非结构化. Hadoop 分三部分组成,1.hdfs hadoop分布式文件系统.2.MapReduce 分布式计算.3.hive 分布式存储. 操作系统:centos6.5 64 环境搭建:1.安装Hadoop,2.安装mysql, 3.安装hive,4,安装jdk Hadoop安装: 下载Hadoop1.0.4,hadoop-1.0.4.tar.gz. wget http://archive.apache.org/dist/hadoop/core

django RESTful研究一环境搭建和理解RESTful

一.环境安装要求: django1.8 python2.7 restful3.2(一定要注意版本,版本不一致会报很多错误,特别是django1.8是在python2.7的基础上才能够运用) 二.环境搭建: pip install djangorestframework pip install markdown       # Markdown support for the browsable API. pip install django-filter 三.理解RESTful: 请参考(htt

spring-oauth-server实践:客户端和服务端环境搭建

客户端:http://localhost:8080/spring-oauth-client/index.jsp 服务端:http://localhost:8080/spring-oauth-server/index.jsp access_token=942090fc-1aa0-4444-8127-57214680df3b 验证业务:http://localhost:8080/spring-oauth-server/m/dashboard?access_token=942090fc-1aa0-44

caffe版faster-RCNN环境搭建

faster-rcnn提出论文: <Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks> faster-rcnn 的算法详解可看这篇博文(清晰易懂,良心博文!): http://blog.csdn.net/shenxiaolu1984/article/details/51152614 faster-rcnn Python版本源码地址:https://github.com/rbgirshic

IDEA开发spring的环境搭建

摘要: 主要讲解使用 IDEA 开发 Spring MVC 的环境搭建,Maven的简单教学. 参考1:https://my.oschina.net/gaussik/blog/385697 参考2:http://www.cnblogs.com/Leo_wl/p/4459274.html 前言 本文是本人开始使用 IDEA 的开端,从 java 框架开始,安装参考以上文章. 一.相关环境 - JDK 1.8.0_45 - Maven 3.3.9 - Tomcat 8.5.12 - MySql 5.

Spring1:Spring简介、环境搭建及源码下载

框架学习前言 这个模块是对于Java框架的学习,主要就是Spring.Hibernate.Ibatis,框架的学习我是这么想的: 1.简单介绍框架,主要是从网上借鉴一些重点 2.尽量说明清楚框架的使用方法以及细节点 3.尽量以自己的理解讲清楚Spring中的一些源代码 Spring是什么 Spring是一款为了解决企业应用开发的复杂性而创建的轻量级Java框架.框架的主要优势之一就是其分层架构,分层架构允许使用者选择哪一个组件,同时为J2EE应用程序开发提供集成的框架.从简单性.可测试性和松耦合