getting started with linux and python by caffe

65
Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Introduction to Linux and Python Building Caffe from scratch and deploy on Linux Lihang Li NLPR CASIA - Robot Vision Group January 20, 2015 Lihang Li NLPR Getting Started With Linux and Python By Caffe

Upload: lihang-li

Post on 17-Jul-2015

2.360 views

Category:

Engineering


11 download

TRANSCRIPT

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Introduction to Linux and PythonBuilding Caffe from scratch and deploy on Linux

Lihang LiNLPR

CASIA - Robot Vision Group

January 20, 2015

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Outline

1 Goal2 Linux Basics

Open SourceHello WorldRecommended Books

3 Fundamentals of PythonWhy PythonA Byte of PythonGood References

4 CaffeBuild Caffe From ScratchPlay With Caffe Examples

5 Conclusion6 What’s Next

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

What’s in this talk?

Linux

Get familiar with basic Linux commands and tools.

Python

Able to read Caffe sample code and hack some simple Pythoncode.

Caffe

Deploy Caffe on Linux by building from source code and learn theexamples.

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Open SourceHello WorldRecommended Books

Outline

1 Goal2 Linux Basics

Open SourceHello WorldRecommended Books

3 Fundamentals of PythonWhy PythonA Byte of PythonGood References

4 CaffeBuild Caffe From ScratchPlay With Caffe Examples

5 Conclusion6 What’s Next

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Open SourceHello WorldRecommended Books

Free Software

What is Free Software?

Free software means the users have the freedom to run, copy,distribute, study, change and improve the software.

Free software is a matter of liberty, not price. To understand theconcept, you should think of free as in free speech, not as in freebeer.

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Open SourceHello WorldRecommended Books

Free Software

Essential Freedoms

The freedom to run the program as you wish, for any purpose(freedom 0).

The freedom to study how the program works, and adapt it toyour needs (freedom 1). Access to the source code is aprecondition for this.

The freedom to redistribute copies so you can help yourneighbor (freedom 2).

The freedom to improve the program, and release yourimprovements to the public, so that the whole communitybenefits (freedom 3). Access to the source code is aprecondition for this.

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Open SourceHello WorldRecommended Books

GNU

What is GNU?

GNU is a Unix-like operating system. That means it is a collectionof many programs: applications, libraries, developer tools, evengames. The development of GNU, started in January 1984, isknown as the GNU Project. Many of the programs in GNU arereleased under the auspices of the GNU Project; those we call GNUpackages.

The name GNU is a recursive acronym for GNU’s Not Unix. GNUis pronounced g’noo, as one syllable, like saying grew but replacingthe r with n.

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Open SourceHello WorldRecommended Books

Linux

Linux or GNU/Linux?

The program in a Unix-like system that allocates machineresources and talk to the hardware is called the kernel. GNU istypically used with a kernel called Linux. This combination is theGNU/Linux operating system. GNU/Linux is used by millions,though many call it Linux by mistake.

GNU’s own kernel, The Hurd, was started in 1990 (before Linuxwas started). Volunteers continue developing the Hurd because itis an interesting technical project.

Without the GNU packages(gcc, make, etc), Linus wouldfind it hard to start writing the Linux kernel.

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Open SourceHello WorldRecommended Books

Linux in a nutshell

Linux Core Concepts

Linux Kernel(Linux itself is an Operating System kernel)

Linux Distro(Ubuntu, Fedora, SUSE, etc)

Linux Shell(Bash, Zsh, Csh, sh, etc)

Linux PackageManager(apt-get, yum, etc)

Linux Toolchain(gcc, make, etc)

Linux Commandline(cd, ls, cp, mv, rm, etc)

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Open SourceHello WorldRecommended Books

Basic Linux Commands

File Operations

ls, cd, pwd, cp, mv, rm, touch, etc

Compression and Decompression

tar, gzip, gunzip, unzip, bzip, etc

Network

ping, hostname, wget, curl, git, etc

Development

vim, gcc, make, ldd, gdb, export, source, etc

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Open SourceHello WorldRecommended Books

Hello Linux!

#include <iostream >

using namespace std;

int main()

{

cout <<"Hello Linux!"<<endl;

return 0;

}

Compile with g++

g++ hello linux.cpp -o hello linux && ./hello linux

Build with make

vim Makefile && make && ./hello linux

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Open SourceHello WorldRecommended Books

Linux Books

Linux Pocket Guide

Linux in a Nutshell

Running Linux

The Linux Command Line

Advanced Linux Programming

Advanced Programming in the Unix Environment(APUE)

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Why PythonA Byte of PythonGood References

Outline

1 Goal2 Linux Basics

Open SourceHello WorldRecommended Books

3 Fundamentals of PythonWhy PythonA Byte of PythonGood References

4 CaffeBuild Caffe From ScratchPlay With Caffe Examples

5 Conclusion6 What’s Next

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Why PythonA Byte of PythonGood References

What is Python?

Python

Python is a great object-oriented, interpreted, and interactiveprogramming language, comparable to Perl, Ruby, Scheme, orJava.

Python Features

Open Source and cross-platform(Linux, MacOS, Windows...)

Uses an elegant syntax, making the programs you write easierto read.

Data types are strongly and dynamically typed.

Automatic memory management.

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Why PythonA Byte of PythonGood References

Hello Python!

#!/usr/bin/env python

myString = "Hello Python!"

print myString

Run Python

Interactive intepreter from the command line(Python orIPython)

Running a script written in Python(python script name.py)

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Why PythonA Byte of PythonGood References

Python Basics - Variables and Assignments

Python Variable

counter = 0 # the integer

miles = 1000.0 # the floating point

name = ’Bob ’ # string

couner = counter + 1 # an incremental statement for

integer

kilometers = 1.609* miles # floating point operation

and assignment

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Why PythonA Byte of PythonGood References

Python Basics - Strings

Python String

pystr = ’PYTHON ’

iscool = ’is cool!’

pystr [0] # ’P’

pystr [2:5] # ’THO ’, from 2 to 4

iscool [:2] # ’is ’, from 0 to 1

pystr + iscool # ’PYTHON is cool!’

pystr*2 # ’PYTHONPYTHON ’

iscool [-1] # ’!’, counting backward

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Why PythonA Byte of PythonGood References

Python Basics - Lists and Tuples

Python List

alist = [1,2,3,4]

alist # [1,2,3,4]

alist [0] # [1]

alist [2:] # [3,4]

alist [:3] # [1,2,3]

alist [1] = 5

alist # [1,5,3,4]

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Why PythonA Byte of PythonGood References

Python Basics - Lists and Tuples

Python Tuple

atuple = (’robots ’,77,93,’try ’)

atuple # (’robots ’,77,93,’try ’)

atuple [:3] # (’robots ’,77,93)

atuple [1] = 5 # TypeError:’tuple ’ object dose not

support item assignment

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Why PythonA Byte of PythonGood References

Python Basics - Dictionaries

Python Dictionary

prices = {’apple ’: 0.40, ’banana ’: 0.50}

prices[’apple ’] # 0.40

prices.keys() # [’apple ’,’banana ’]

prices[’orange ’] = 0.60

prices # {’apple ’: 0.40, ’banana ’: 0.50,

’orange ’: 0.60}

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Why PythonA Byte of PythonGood References

Python Basics - Conditional Statments

Python If-Else

if condition:

# Code to run if condition true

elif other_cond:

# Code to run if other_cond and not condition

else:

# Code to run if not (condition and other_cond)

# Python has a ternary operator

x = a if condition else b

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Why PythonA Byte of PythonGood References

Python Basics - Loops

Pyton For Loop

for i in iterator:

# Do something with i

for i in iterator1:

for j in iterator2:

# Do something with i and j

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Why PythonA Byte of PythonGood References

Python Basics - Loops

Python While Loop

while some_condition:

# Do something

# Update condition

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Why PythonA Byte of PythonGood References

Python Basics - List comprehensions

Python List Comprehensions

# List comprehensions are syntactically dense method

to build lists

# Basic

x = [item for item in iterable]

# Can be combined with logicals

x = [item for item in iterable if item >0]

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Why PythonA Byte of PythonGood References

Python Basics - Functions

Python Functions

def greet(name):

print ’Hello ’, name

greet(’Jack ’)

greet(’Jill ’)

greet(’Bob ’)

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Why PythonA Byte of PythonGood References

Python Basics - Functions

Python Fuctions

# Basic

function ()

out = function(arg1 , arg2 , ...)

# Return multiple outputs

a,b,c = function ()

# Two input methods

function(x,y) # In order(positional)

function(file=’input ,csv ’, skiprows =10) # keyword

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Why PythonA Byte of PythonGood References

Python Basics - I/O

Python Openning Files

# indent your Python code to put into an email

import glob

# glob supports Unix style pathname extensions

python_files = glob.glob(’*.py ’)

for file_name in sorted(python_files):

print ’ ------’ + file_name

with open(file_name) as f:

for line in f:

print ’ ’ + line.rstrip ()

print

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Why PythonA Byte of PythonGood References

Python Basics - Packages and Modules

Python Modules and Packages

Modules in Python are simply Python files with the .py extension,which implement a set of functions. Modules are imported fromother modules using the import command.

Packages are namespaces which contain multiple packages andmodules themselves. They are simply directories, which MUSTcontain a special file called init .py.

Python Import Modules

import numpy as np

import caffe

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Why PythonA Byte of PythonGood References

Scientific Python

SciPy

SciPy(http://www.scipy.org/) is an open source library ofscientific tools for Python. SciPy supplements the popular NumPymodule, gathering a variety of high level science and engineeringmodules together as a single package. SciPy includes modules forlinear algebra, optimization, integration, special functions, signaland image processing, statistics, genetic algorithms, ODE solvers,and others.

NumPy

Numerical Python(http://www.numpy.org/) adds a fast,compact, multidimensional array facility to Python. NumPy is thesuccessor to both Numeric and Numarray.

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Why PythonA Byte of PythonGood References

Python Resources

Links

https://www.python.org/

https://wiki.python.org/

https://docs.python.org/

https://docs.python.org/2/tutorial/

Books

A Byte of Python

See also:https://wiki.python.org/moin/IntroductoryBooks

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Build Caffe From ScratchPlay With Caffe Examples

Outline

1 Goal2 Linux Basics

Open SourceHello WorldRecommended Books

3 Fundamentals of PythonWhy PythonA Byte of PythonGood References

4 CaffeBuild Caffe From ScratchPlay With Caffe Examples

5 Conclusion6 What’s Next

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Build Caffe From ScratchPlay With Caffe Examples

What is Caffe?

Caffe is a deep learning framework developed with cleanliness,readability, and speed in mind. It was created by Yangqing Jiaduring his PhD at UC Berkeley, and is in active development by theBerkeley Vision and Learning Center (BVLC) and by communitycontributors. Caffe is released under the BSD 2-Clause license.

With Caffe, you can do whatever Deep Learning can doeasily!

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Build Caffe From ScratchPlay With Caffe Examples

Why use Caffe?

Clean architecture enables rapid deployment.

Readable & modifiable implementation fosters activedevelopment.

Speed makes Caffe perfect for industry use. Caffe can processover 40M images per day with a single NVIDIA K40 or TitanGPU*. Thats 5 ms/image in training, and 2 ms/image in test.We believe that Caffe is the fastest CNN implementationavailable.

Community: Caffe already powers academic research projects,startup prototypes, and even large-scale industrial applicationsin vision, speech, and multimedia. There is an activediscussion and support community on Github.

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Build Caffe From ScratchPlay With Caffe Examples

Caffe-Core Software Packages

Caffe(http://caffe.berkeleyvision.org/)

CUDA(https://developer.nvidia.com/)

cuDNN(https://developer.nvidia.com/cuDNN)

OpenBLAS(http://www.openblas.net/)

OpenCV(http://opencv.org/)

Boost(http://www.boost.org/)

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Build Caffe From ScratchPlay With Caffe Examples

Caffe-Other Dependencies

protobuf(https://github.com/google/protobuf)

google-glog(https://code.google.com/p/google-glog/)

gflags(https://code.google.com/p/gflags/)

snappy(https://github.com/google/snappy)

leveldb(https://github.com/google/leveldb)

lmdb(http://symas.com/mdb/)

hdf5(http://www.hdfgroup.org/HDF5/)

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Build Caffe From ScratchPlay With Caffe Examples

Caffe-Build Tools

CMake(http://www.cmake.org/)

make(http://www.gnu.org/software/make/)

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Build Caffe From ScratchPlay With Caffe Examples

Build from Source vs. Package Manager

Build from Source

Much more customization and tuning

Usually by invoking ./configure && make && make install

A disaster when tons of dependencies arise

Package Manager

Install everything using just one simple command, such assudo apt-get install meshlab

Can’t be altered since the installed packages are pre-built

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Build Caffe From ScratchPlay With Caffe Examples

Get Caffe Source Code

Get Caffe

git clone https :// github.com/BVLC/caffe.git

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Build Caffe From ScratchPlay With Caffe Examples

Install OpenBLAS

Install OpenBLAS

git clone https :// github.com/xianyi/OpenBLAS.git

make FC=gfortran NO_AFFINITY =1 USE_OPENMP =1

mkdir -p ~/ local/OpenBLAS

make PREFIX=$HOME/local/OpenBLAS install

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Build Caffe From ScratchPlay With Caffe Examples

Install protobuf

Install protobuf

wget https :// protobuf.googlecode.com/files/protobuf

-2.5.0. tar.gz

tar zxvf protobuf -2.5.0. tar.gz

cd protobuf -2.5.0

./ configure --prefix=$HOME/local

make

make install

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Build Caffe From ScratchPlay With Caffe Examples

Install snappy

Install snappy

wget https:// snappy.googlecode.com/files/snappy -1.1.1.

tar.gz

tar zxvf snappy -1.1.1. tar.gz

cd snappy -1.1.1

./ configure --prefix=$HOME/local

make

make install

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Build Caffe From ScratchPlay With Caffe Examples

Install leveldb

Install leveldb

wget https:// leveldb.googlecode.com/files/leveldb

-1.15.0. tar.gz

tar zxvf leveldb -1.15.0. tar.gz

cd leveldb -1.15.0

make

cp -av libleveldb .* $HOME/local/lib/

cp -av include/leveldb $HOME/local/include/

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Build Caffe From ScratchPlay With Caffe Examples

Install OpenCV

Install OpenCV

wget https:// github.com/Itseez/opencv/archive /2.4.8.

tar.gz

tar zxvf 2.4.8. tar.gz && cd opencv -2.4.8

mkdir release && cd release

cmake -D CMAKE_BUILD_TYPE=RELEASE -D

CMAKE_INSTALL_PREFIX=$HOME/local -D

BUILD_opencv_gpu=OFF ..

make && make install

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Build Caffe From ScratchPlay With Caffe Examples

Install Boost

Install Boost

wget http://cznic.dl.sourceforge.net/project/boost/

boost /1.55.0/ boost_1_55_0.tar.gz

./ bootstrap.sh --prefix=$HOME/local

./b2 -j 32

./b2 install

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Build Caffe From ScratchPlay With Caffe Examples

Install google-glog

Install google-glog

wget https://google -glog.googlecode.com/files/glog

-0.3.3. tar.gz

tar zxvf glog -0.3.3. tar.gz

cd glog -0.3.3

./ configure --prefix=$HOME/local

make

make install

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Build Caffe From ScratchPlay With Caffe Examples

Install gflags

Install gflags

git clone https://code.google.com/p/gflags/

cd gflags

mkdir build && cd build

CXXFLAGS="-fPIC" cmake -D CMAKE_INSTALL_PREFIX=$HOME/

local ..

make

make install

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Build Caffe From ScratchPlay With Caffe Examples

Install lmdb

Install lmdb

git clone https:// gitorious.org/mdb/mdb.git

cd mdb/libraries/liblmdb

make

make prefix=$HOME/local install

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Build Caffe From ScratchPlay With Caffe Examples

Install hdf5

Install hdf5

wget http://www.hdfgroup.org/ftp/HDF5/current/src/hdf5

-1.8.14. tar.gz

tar zxvf hdf5 -1.8.14. tar.gz && cd hdf5 -1.8.14

./ configure --prefix=$HOME/local

make && make check # run test suite.

make install && make check -install # verify

installation.

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Build Caffe From ScratchPlay With Caffe Examples

Install cuDNN

Install cuDNN

cp /data1/NLPRMNT/public/cudnn/lib64 /* ~/local/lib

cp /data1/NLPRMNT/public/cudnn/include /* ~/local/

include

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Build Caffe From ScratchPlay With Caffe Examples

Modify Path

Modify Path

vim ~/. bashrc

# Take CUDA for example

export PATH=/usr/local/cuda/bin:$PATH

export LD_LIBRARY_PATH =/usr/local/cuda/lib64:

$LD_LIBRARY_PATH

source ~/. bashrc

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Build Caffe From ScratchPlay With Caffe Examples

Build Caffe

Build Caffe

cp Makefile.config.example Makefile.config

vim Makefile.config

============[ Makefile.config]

USE_CUDNN := 1

CUDA_DIR := /usr/local/cuda

INCLUDE_DIRS := /data1/NLPRMNT/xxx/local/include

LIBRARY_DIRS := /data1/NLPRMNT/xxx/local/lib

============[ Makefile.config]

make all -j8

make test -j8

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Build Caffe From ScratchPlay With Caffe Examples

Caffe Usage

Interfaces

Caffe has command line, Python, and MATLAB interfaces forday-to-day usage, interfacing with research code, and rapidprototyping. While Caffe is a C++ library at heart and it exposes amodular interface for development, not every occasion calls forcustom compilation. The cmdcaffe, pycaffe, and matcaffeinterfaces are here for you.

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Build Caffe From ScratchPlay With Caffe Examples

Caffe Interface - cmdcaffe

cmdcaffe

The command line interface cmdcaffe is the caffe tool for modeltraining, scoring, and diagnostics. Run caffe without anyarguments for help. This tool and others are found incaffe/build/tools.

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Build Caffe From ScratchPlay With Caffe Examples

cmdcaffe - Training

caffe train learns models from scratch, resumes learning from savedsnapshots, and fine-tunes models to new data and tasks. Alltraining requires a solver configuration through the -solversolver.prototxt argument. Resuming requires the -snapshotmodel iter 1000.solverstate argument to load the solver snapshot.

# train LeNet

caffe train -solver examples/mnist/lenet_solver.

prototxt

# train on GPU 2

caffe train -solver examples/mnist/lenet_solver.

prototxt -gpu 2

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Build Caffe From ScratchPlay With Caffe Examples

cmdcaffe - Testing

caffe test scores models by running them in the test phase andreports the net output as its score. The net architecture must beproperly defined to output an accuracy measure or loss as itsoutput. The per-batch score is reported and then the grandaverage is reported last.

# score the learned LeNet model on the validation set

as defined in the model architeture

lenet_train_test.prototxt

caffe test -model examples/mnist/lenet_train_test.

prototxt -weights examples/mnist/lenet_iter_10000

-gpu 0 -iterations 100

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Build Caffe From ScratchPlay With Caffe Examples

cmdcaffe - Benchmarking

caffe time benchmarks model execution layer-by-layer throughtiming and synchronization. This is useful to check systemperformance and measure relative execution times for models.

# time LeNet training on CPU for 10 iterations

caffe time -model examples/mnist/lenet_train_test.

prototxt -iterations 10

# time LeNet training on GPU for the default 50

iterations

caffe time -model examples/mnist/lenet_train_test.

prototxt -gpu 0

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Build Caffe From ScratchPlay With Caffe Examples

cmdcaffe - Diagnostics

caffe device query reports GPU details for reference and checkingdevice ordinals for running on a given device in multi-GPUmachines.

# query the first device

caffe device_query -gpu 0

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Build Caffe From ScratchPlay With Caffe Examples

Caffe Interface - pycaffe

pycaffe

The Python interface pycaffe is the caffe module and its scripts incaffe/python. import caffe to load models, do forward andbackward, handle IO, visualize networks, and even instrumentmodel solving. All model data, derivatives, and parameters areexposed for reading and writing.

Compile pycaffe by make pycaffe. The module dircaffe/python/caffe should be installed in your PYTHONPATH forimport caffe.

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Build Caffe From ScratchPlay With Caffe Examples

pycaffe

caffe.Net is the central interface for loading, configuring, andrunning models. caffe.Classsifier and caffe.Detector provideconvenience interfaces for common tasks.

caffe.SGDSolver exposes the solving interface.

caffe.io handles input/output with preprocessing and protocolbuffers.

caffe.draw visualizes network architectures.

Caffe blobs are exposed as numpy ndarrays for ease-of-use andefficiency.

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Build Caffe From ScratchPlay With Caffe Examples

Caffe Interface - matcaffe

The MATLAB interface matcaffe is the caffe mex and its helperm-files in caffe/matlab. Load models, do forward and backward,extract output and read-only model weights, and load thebinaryproto format mean as a matrix.

Compile matcaffe by make matcaffe.

A MATLAB demo is in caffe/matlab/caffe/matcaffe demo.m

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Outline

1 Goal2 Linux Basics

Open SourceHello WorldRecommended Books

3 Fundamentals of PythonWhy PythonA Byte of PythonGood References

4 CaffeBuild Caffe From ScratchPlay With Caffe Examples

5 Conclusion6 What’s Next

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Linux

We have learned basic Linux commands and tools(such as wget,make) for building a software package from source.

Python

By learning basic Python grammars, the audience are expected tobe able to read the source code of Caffe Python samples and dosome simple hack.

Caffe

Through learning how to deploy Caffe on Linux by building fromsource code, people should find it comfortable to deploy othercomplicated software packages by reading the README or helpfile shipped with the packages.

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Outline

1 Goal2 Linux Basics

Open SourceHello WorldRecommended Books

3 Fundamentals of PythonWhy PythonA Byte of PythonGood References

4 CaffeBuild Caffe From ScratchPlay With Caffe Examples

5 Conclusion6 What’s Next

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

Enjoy Caffe, Enjoy Open Source!

Deep Learning

Deploy Caffe on Linux by yourself

Dive into Linux and Python by referencing great books

Discuss with others and share experience with Caffe

Use Caffe to tackle your Deep Learning problems

Contribute your own source code to Caffe to make it better!

Lihang Li NLPR Getting Started With Linux and Python By Caffe

GoalLinux Basics

Fundamentals of PythonCaffe

ConclusionWhat’s Next

The End

Thank You & Have Fun!

Lihang Li NLPR Getting Started With Linux and Python By Caffe