Side note: You're supposed to to this on Ubuntu 16 or 15. If you have ubuntu 17 it's a lot easier, just follow the original tutorial. If you have ubuntu < 16, what about an update?
The Caffe Framework is a known tool in the deep learning community that can be used to build, test and run CNNs. It was developed by Berkeley Vision and Learning Center and is used by some famous companies (like Facebook) in their deep learning projects. Its core is written in C++ but it comes with some handy python and matlab bindings for a less bumpy development. The original research from which we took the idea of ours used Caffe and we were curious to know about its capabilities, so we’ve decided to adopt this framework as well. The setup part is a bit complicated and the documentation is not extensive as the ones from similar projects (such as TensorFlow) but after some time it’s all nice and clear.
I’ve decided to use an instance in Amazon AWS to run the project. Caffe has support for processing in GPU and trust me this is necessary, I tried to run the CNN we’re using
just for fun in my humble Intel i5 PC and the process took 4 hours with small images (128 x 128) and a small number of images (16k). For the original research we’d need images twice as large (256 x256) and about 44k of them, therefore if I wanted to finish my research this year I’d need a better setup.
The instance I used is available in amazon aws community instances. It’s the one used in the Stanford course cs231n and it comes with all the necessary software installed. It’s the Amazon Machine Image, cs231n_caffe_torch7_keras_lasagne_v2 located in the North Carolina region so the region needs to be set to that if you want to run it. Be sure to check g2.2xlarge as the instance type so we’ll have support for NVIDIA CUDA (an interface to run software on GPUs), the tutorial I followed as this one.
Of course the point of this post is to teach you how to install the framework, therefore if you want to build your own setup or just want to try some small networks in your home computer, follow the steps to install the framework.
Like with OpenCV for example you’ll need to download and build caffe on your machine, but firstly we need to install some dependencies, so fire up these commands:
sudo apt-get update sudo apt-get upgrade sudo apt-get install -y build-essential cmake git pkg-config sudo apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev libhdf5-serial-dev protobuf-compiler sudo apt-get install -y libatlas-base-dev sudo apt-get install -y --no-install-recommends libboost-all-dev sudo apt-get install -y libgflags-dev libgoogle-glog-dev liblmdb-dev
Install pip for managing python packages more easily:
sudo apt-get install -y python-pip
Install python developer tools. I prefer python 2.7, so I’ll use this as an example. Install scipy and numpy as well:
sudo apt-get install -y python-dev sudo apt-get install -y python-numpy python-scipy
Follow this tutorial to install OpenCV3.
By now you have all the necessary stuff to build caffe, so clone or download the repo in you preferred location. Then run in the root folder:
cp Makefile.config.example Makefile.config
This will simply create a base configuration file so you can configure your build before running it. By default caffe is expected to run on a GPU enabled machine (you know why) to run on a normal PC with CPU only simply uncomment the line:
CPU_ONLY := 1
Please, make sure that you have the lines bellow in your Makefile.config
PYTHON_INCLUDE := /usr/include/python2.7 /usr/local/lib/python2.7/dist-packages/numpy/core/include WITH_PYTHON_LAYER := 1 INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial
LIBRARIES += glog gflags protobuf leveldb snappy \ lmdb boost_system boost_filesystem hdf5_hl hdf5 m \ opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs opencv_videoio
Now you can build it:
make all make test make runtest make pycaffe
The last make command will build the python bindings for caffe. After the build is complete you’ll se a build folder in the caffe root with the necessary tools to run your experiments.
If you have a PC with GPU (NVIDIA) please refer to the original tutorial at the side note (top of the post) to learn how to enable GPU support. If you plan to run large networks either use AWS or build a nice powerful setup.
I think that’s it guys. Stay wise.