Ubuntu 14.04 安装Caffe(CPU) 且支持 PYTHON接口

来源:互联网 发布:网络测试命令 编辑:程序博客网 时间:2024/06/06 12:23

                        Caffe Installation on Ubuntu 14.04 (CPU) with PYTHON support

    本篇文章将会详细的介绍关于Ubuntu14.04系统,安装的Caffe(CPU版)的每个过程。一旦我们安装完成,我们可以通过使用caffe测试

Generating images with Google’s “INCEPTIONISM” – deepdream - See more at: http://hanzratech.in/2015/07/27/installing-caffe-on-ubuntu.html#sthash.GeX2Iv0R.dpuf
Generating images with Google’s “INCEPTIONISM” – deepdream - See more at: http://hanzratech.in/2015/07/27/installing-caffe-on-ubuntu.html#sthash.GeX2Iv0R.dpuf
Generating images with Googles's"INCEPTIONISM"--deepdream是否成功.我们会使用一些公用的图片使用deepdream来泛化这些图片。废话不多说,那就让我们开始吧。:smile:

    首先,让我们在$HOME下创建一个名为deep-learning的目录,我们将在这个在这个目录里下载所有所需要的包。

cd ~ mkdir deep-learningcd deep-learning

1、建立依赖关系包

    为了让caffe编译成功,我们需要首先安装一些依赖包。在终端里执行下面的命令.

    提示:博主在亲自安装的时候,发现有些包会安装不上。所以,更换了一些包的安装顺序就可以了。大家可以多试试。

   

NOTE -> Since we will not be using GPUs, we do not require CUDA installation. - See more at: http://hanzratech.in/2015/07/27/installing-caffe-on-ubuntu.html#sthash.GeX2Iv0R.dpuf
注意:因为我们不使用GPU,所以我们无需安装cuda.

# General Dependencies 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 # BLAS -- for better CPU performance sudo apt-get install libatlas-base-dev # Python -- It comes preinstalled on Ubuntu 14.04 # Required if you want to use Python wrappers for Caffe sudo apt-get install the python-dev # Remaining dependencies sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev 

安装依赖包的另一版本(上面的三条指令成功,则无需在试!):

sudo apt-get install libatlas-base-devsudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev libhdf5-serial-devsudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler


2、编译和安装Caffe

caffe的包被公布在GitHub上。通过在终端输入下面的命令来完成caffe包的克隆。

cd ~/deep-learning git clone http://github.com/BVLC/caffe.git cd caffe

Makefile.config.example文件的内容是验证文件的模板。我们使用他来重写Makefile。config文件。

cp Makefile.config.example Makefile.config

在Makefile.config文件中我们需要设置的是使用CPU还是GPU。打开你最喜欢的编辑器,取消注释CPU_ONLY:=1

CPU_ONLY := 1
(很有可能在第8行)像下面这样:

8 CPU_ONLY := 1

设置完验证文件后,接下的步骤就是编译caffe了:smile:

make all make test make runtest

If you get an OpenCV undefined reference error in make all as shown below follow the instructions below else move to the section 3. - See more at: http://hanzratech.in/2015/07/27/installing-caffe-on-ubuntu.html#sthash.GeX2Iv0R.dpuf

注意

undefined reference error
undefined reference error
undefined reference error
undefined reference error
undefined reference error
如果你编译make all的时候返回OpenCV
undefined reference error
undefined refernce error

可能像下面所示

.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 make: *** [.build_release/tools/caffe.bin] Error 1
点击这里可以看到更加详细的解答(点击打开链接)

为了更正这个错误,我们需要在opencv_imgcodecs在176行(可能)添加下面的内容:

174 LIBRARIES += glog gflags protobuf leveldb snappy \ 175 mdb boost_system hdf5_hl hdf5 m \ 176 opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs


现在我们清楚build文件下的所有内容。这是一个很重要的步骤,不然会有其他的错误产生。

rm -rf ./build/*

现在,我们重新开始上面失败的指令。

make all make test make runtest

3、增加PYTHON支持

为了增加python的支持,我们需要在终端下执行下面的命令。我们需要python能够支持运行deepdream下的代码。

cd ~/deep-learning/caffe make pycaffe echo export PYTHONPATH=~/deep-learning/caffe/python:$PYTHONPATH >> ~/.bashrc

4. Running the INCEPTIONISM code

4.1. Download the GoogLeNet model and clone the deepdream GitHub repository.

cd ~/deep-learningwget http://dl.caffe.berkeleyvision.org/bvlc_googlenet.caffemodel mv bvlc_googlenet.caffemodel caffe/models/bvlc_googlenet/ git clone https://github.com/google/deepdream.git

4.2. Install the dependencies
sudo pip install "ipython[all]" sudo pip install numpy sudo pip install scipy sudo pip install protobufsudo pip install skimage

4.3. Run the IPython Notebook

.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 returned1exitstatusmake: *** [.build_release/tools/caffe.bin] Error 1 - See more at: http://hanzratech.in/2015/07/27/installing-caffe-on-ubuntu.html#sthash.GeX2Iv0R.dpuf

cd ~/deep=learning/deepdream ipython notebook

Now the IPython notebook dashboard will open up in your default browser as shown below.

Now the IPython notebook dashboard will open up in your default browser as shown below. - See more at: http://hanzratech.in/2015/07/27/installing-caffe-on-ubuntu.html#sthash.GeX2Iv0R.dpuf

undefined reference error
Snapshot of IPython Notebook Dashboard

In the list of files, click on dream.ipynb and you will get an output as shown in the figure below.

Snapshot of IPython Notebook



So, this is it ! Use this IPython Notebook to play with the deepdream code to generate some awesome images. I hope you liked the post and THANK YOU :smile: for reading.


原文:http://hanzratech.in/2015/07/27/installing-caffe-on-ubuntu.html

In this tutorial, I will detail the steps for installing Caffe on a non-GPU(CPU) machine with Ubuntu 14.04 OS. Once we are done with the installation, we’ll also test theGOOGLE INCEPTIONISM (deepdream) code which uses Caffe. This is a follow up post to my last post –Generating images with Google’s “INCEPTIONISM” – deepdream where I had shared some awesome images generated usingdeepdream code. So, let’s get our hands dirty straight away:smile:.

Firstly, let’s make a directory named deep-learning in the$HOME folder where we will download all the packages.

- See more at: http://hanzratech.in/2015/07/27/installing-caffe-on-ubuntu.html#sthash.GeX2Iv0R.dpuf
In this tutorial, I will detail the steps for installing Caffe on a non-GPU(CPU) machine with Ubuntu 14.04 OS. Once we are done with the installation, we’ll also test the - See more at: http://hanzratech.in/2015/07/27/installing-caffe-on-ubuntu.html#sthash.GeX2Iv0R.dpuf
In this tutorial, I will detail the steps for installing Caffe on a non-GPU(CPU) machine with Ubuntu 14.04 OS. Once we are done with the installation, we’ll also test the - See more at: http://hanzratech.in/2015/07/27/installing-caffe-on-ubuntu.html#sthash.GeX2Iv0R.dpuf
In this tutorial, I will detail the steps for installing Caffe on a non-GPU(CPU) machine with Ubuntu 14.04 OS. Once we are done with the installation, we’ll also test the - See more at: http://hanzratech.in/2015/07/27/installing-caffe-on-ubuntu.html#sthash.GeX2Iv0R.dp

In this tutorial, I will detail the steps for installing Caffe on a non-GPU(CPU) machine with Ubuntu 14.04 OS. Once we are done with the installation, we’ll also test theGOOGLE INCEPTIONISM (deepdream) code which uses Caffe. This is a follow up post to my last post –Generating images with Google’s “INCEPTIONISM” – deepdream where I had shared some awesome images generated usingdeepdream code. So, let’s get our hands dirty straight away:smile:.

Firstly, let’s make a directory named deep-learning in the$HOME folder where we will download all the packages.

- See more at: http://hanzratech.in/2015/07/27/installing-caffe-on-ubuntu.html#sthash.GeX2Iv0R.dpuf

In this tutorial, I will detail the steps for installing Caffe on a non-GPU(CPU) machine with Ubuntu 14.04 OS. Once we are done with the installation, we’ll also test theGOOGLE INCEPTIONISM (deepdream) code which uses Caffe. This is a follow up post to my last post –Generating images with Google’s “INCEPTIONISM” – deepdream where I had shared some awesome images generated usingdeepdream code. So, let’s get our hands dirty straight away:smile:.

Firstly, let’s make a directory named deep-learning in the$HOME folder where we will download all the packages.

- See more at: http://hanzratech.in/2015/07/27/installing-caffe-on-ubuntu.html#sthash.GeX2Iv0R.dpuf

In this tutorial, I will detail the steps for installing Caffe on a non-GPU(CPU) machine with Ubuntu 14.04 OS. Once we are done with the installation, we’ll also test theGOOGLE INCEPTIONISM (deepdream) code which uses Caffe. This is a follow up post to my last post –Generating images with Google’s “INCEPTIONISM” – deepdream where I had shared some awesome images generated usingdeepdream code. So, let’s get our hands dirty straight away:smile:.

Firstly, let’s make a directory named deep-learning in the$HOME folder where we will download all the packages.

- See more at: http://hanzratech.in/2015/07/27/installing-caffe-on-ubuntu.html#sthash.GeX2Iv0R.dpuf

2 0
原创粉丝点击