SlideShare a Scribd company logo
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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Outline
1 Goal
2 Linux Basics
Open Source
Hello World
Recommended Books
3 Fundamentals of Python
Why Python
A Byte of Python
Good References
4 Caffe
Build Caffe From Scratch
Play With Caffe Examples
5 Conclusion
6 What’s Next
Lihang Li NLPR Getting Started With Linux and Python By Caffe
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’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 Python
code.
Caffe
Deploy Caffe on Linux by building from source code and learn the
examples.
Lihang Li NLPR Getting Started With Linux and Python By Caffe
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Open Source
Hello World
Recommended Books
Outline
1 Goal
2 Linux Basics
Open Source
Hello World
Recommended Books
3 Fundamentals of Python
Why Python
A Byte of Python
Good References
4 Caffe
Build Caffe From Scratch
Play With Caffe Examples
5 Conclusion
6 What’s Next
Lihang Li NLPR Getting Started With Linux and Python By Caffe
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Open Source
Hello World
Recommended 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 the
concept, you should think of free as in free speech, not as in free
beer.
Lihang Li NLPR Getting Started With Linux and Python By Caffe
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Open Source
Hello World
Recommended 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 to
your needs (freedom 1). Access to the source code is a
precondition for this.
The freedom to redistribute copies so you can help your
neighbor (freedom 2).
The freedom to improve the program, and release your
improvements to the public, so that the whole community
benefits (freedom 3). Access to the source code is a
precondition for this.
Lihang Li NLPR Getting Started With Linux and Python By Caffe
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Open Source
Hello World
Recommended Books
GNU
What is GNU?
GNU is a Unix-like operating system. That means it is a collection
of many programs: applications, libraries, developer tools, even
games. The development of GNU, started in January 1984, is
known as the GNU Project. Many of the programs in GNU are
released under the auspices of the GNU Project; those we call GNU
packages.
The name GNU is a recursive acronym for GNU’s Not Unix. GNU
is pronounced g’noo, as one syllable, like saying grew but replacing
the r with n.
Lihang Li NLPR Getting Started With Linux and Python By Caffe
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Open Source
Hello World
Recommended Books
Linux
Linux or GNU/Linux?
The program in a Unix-like system that allocates machine
resources and talk to the hardware is called the kernel. GNU is
typically used with a kernel called Linux. This combination is the
GNU/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 Linux
was started). Volunteers continue developing the Hurd because it
is an interesting technical project.
Without the GNU packages(gcc, make, etc), Linus would
find it hard to start writing the Linux kernel.
Lihang Li NLPR Getting Started With Linux and Python By Caffe
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Open Source
Hello World
Recommended 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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Open Source
Hello World
Recommended 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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Open Source
Hello World
Recommended 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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Open Source
Hello World
Recommended 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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Why Python
A Byte of Python
Good References
Outline
1 Goal
2 Linux Basics
Open Source
Hello World
Recommended Books
3 Fundamentals of Python
Why Python
A Byte of Python
Good References
4 Caffe
Build Caffe From Scratch
Play With Caffe Examples
5 Conclusion
6 What’s Next
Lihang Li NLPR Getting Started With Linux and Python By Caffe
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Why Python
A Byte of Python
Good References
What is Python?
Python
Python is a great object-oriented, interpreted, and interactive
programming language, comparable to Perl, Ruby, Scheme, or
Java.
Python Features
Open Source and cross-platform(Linux, MacOS, Windows...)
Uses an elegant syntax, making the programs you write easier
to read.
Data types are strongly and dynamically typed.
Automatic memory management.
Lihang Li NLPR Getting Started With Linux and Python By Caffe
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Why Python
A Byte of Python
Good References
Hello Python!
#!/usr/bin/env python
myString = "Hello Python!"
print myString
Run Python
Interactive intepreter from the command line(Python or
IPython)
Running a script written in Python(python script name.py)
Lihang Li NLPR Getting Started With Linux and Python By Caffe
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Why Python
A Byte of Python
Good 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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Why Python
A Byte of Python
Good 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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Why Python
A Byte of Python
Good 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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Why Python
A Byte of Python
Good 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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Why Python
A Byte of Python
Good 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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Why Python
A Byte of Python
Good 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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Why Python
A Byte of Python
Good 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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Why Python
A Byte of Python
Good 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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Why Python
A Byte of Python
Good 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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Why Python
A Byte of Python
Good 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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Why Python
A Byte of Python
Good 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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Why Python
A Byte of Python
Good 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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Why Python
A Byte of Python
Good 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 from
other modules using the import command.
Packages are namespaces which contain multiple packages and
modules themselves. They are simply directories, which MUST
contain 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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Why Python
A Byte of Python
Good References
Scientific Python
SciPy
SciPy(http://www.scipy.org/) is an open source library of
scientific tools for Python. SciPy supplements the popular NumPy
module, gathering a variety of high level science and engineering
modules together as a single package. SciPy includes modules for
linear algebra, optimization, integration, special functions, signal
and 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 the
successor to both Numeric and Numarray.
Lihang Li NLPR Getting Started With Linux and Python By Caffe
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Why Python
A Byte of Python
Good 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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Build Caffe From Scratch
Play With Caffe Examples
Outline
1 Goal
2 Linux Basics
Open Source
Hello World
Recommended Books
3 Fundamentals of Python
Why Python
A Byte of Python
Good References
4 Caffe
Build Caffe From Scratch
Play With Caffe Examples
5 Conclusion
6 What’s Next
Lihang Li NLPR Getting Started With Linux and Python By Caffe
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Build Caffe From Scratch
Play 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 Jia
during his PhD at UC Berkeley, and is in active development by the
Berkeley Vision and Learning Center (BVLC) and by community
contributors. Caffe is released under the BSD 2-Clause license.
With Caffe, you can do whatever Deep Learning can do
easily!
Lihang Li NLPR Getting Started With Linux and Python By Caffe
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Build Caffe From Scratch
Play With Caffe Examples
Why use Caffe?
Clean architecture enables rapid deployment.
Readable & modifiable implementation fosters active
development.
Speed makes Caffe perfect for industry use. Caffe can process
over 40M images per day with a single NVIDIA K40 or Titan
GPU*. Thats 5 ms/image in training, and 2 ms/image in test.
We believe that Caffe is the fastest CNN implementation
available.
Community: Caffe already powers academic research projects,
startup prototypes, and even large-scale industrial applications
in vision, speech, and multimedia. There is an active
discussion and support community on Github.
Lihang Li NLPR Getting Started With Linux and Python By Caffe
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Build Caffe From Scratch
Play 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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Build Caffe From Scratch
Play 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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Build Caffe From Scratch
Play 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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Build Caffe From Scratch
Play 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 as
sudo 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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Build Caffe From Scratch
Play 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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Build Caffe From Scratch
Play 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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Build Caffe From Scratch
Play 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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Build Caffe From Scratch
Play 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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Build Caffe From Scratch
Play 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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Build Caffe From Scratch
Play 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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Build Caffe From Scratch
Play 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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Build Caffe From Scratch
Play 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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Build Caffe From Scratch
Play 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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Build Caffe From Scratch
Play 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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Build Caffe From Scratch
Play 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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Build Caffe From Scratch
Play 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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Build Caffe From Scratch
Play 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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Build Caffe From Scratch
Play 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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Build Caffe From Scratch
Play With Caffe Examples
Caffe Usage
Interfaces
Caffe has command line, Python, and MATLAB interfaces for
day-to-day usage, interfacing with research code, and rapid
prototyping. While Caffe is a C++ library at heart and it exposes a
modular interface for development, not every occasion calls for
custom compilation. The cmdcaffe, pycaffe, and matcaffe
interfaces are here for you.
Lihang Li NLPR Getting Started With Linux and Python By Caffe
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Build Caffe From Scratch
Play With Caffe Examples
Caffe Interface - cmdcaffe
cmdcaffe
The command line interface cmdcaffe is the caffe tool for model
training, scoring, and diagnostics. Run caffe without any
arguments for help. This tool and others are found in
caffe/build/tools.
Lihang Li NLPR Getting Started With Linux and Python By Caffe
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Build Caffe From Scratch
Play With Caffe Examples
cmdcaffe - Training
caffe train learns models from scratch, resumes learning from saved
snapshots, and fine-tunes models to new data and tasks. All
training requires a solver configuration through the -solver
solver.prototxt argument. Resuming requires the -snapshot
model 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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Build Caffe From Scratch
Play With Caffe Examples
cmdcaffe - Testing
caffe test scores models by running them in the test phase and
reports the net output as its score. The net architecture must be
properly defined to output an accuracy measure or loss as its
output. The per-batch score is reported and then the grand
average 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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Build Caffe From Scratch
Play With Caffe Examples
cmdcaffe - Benchmarking
caffe time benchmarks model execution layer-by-layer through
timing and synchronization. This is useful to check system
performance 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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Build Caffe From Scratch
Play With Caffe Examples
cmdcaffe - Diagnostics
caffe device query reports GPU details for reference and checking
device ordinals for running on a given device in multi-GPU
machines.
# query the first device
caffe device_query -gpu 0
Lihang Li NLPR Getting Started With Linux and Python By Caffe
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Build Caffe From Scratch
Play With Caffe Examples
Caffe Interface - pycaffe
pycaffe
The Python interface pycaffe is the caffe module and its scripts in
caffe/python. import caffe to load models, do forward and
backward, handle IO, visualize networks, and even instrument
model solving. All model data, derivatives, and parameters are
exposed for reading and writing.
Compile pycaffe by make pycaffe. The module dir
caffe/python/caffe should be installed in your PYTHONPATH for
import caffe.
Lihang Li NLPR Getting Started With Linux and Python By Caffe
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Build Caffe From Scratch
Play With Caffe Examples
pycaffe
caffe.Net is the central interface for loading, configuring, and
running models. caffe.Classsifier and caffe.Detector provide
convenience interfaces for common tasks.
caffe.SGDSolver exposes the solving interface.
caffe.io handles input/output with preprocessing and protocol
buffers.
caffe.draw visualizes network architectures.
Caffe blobs are exposed as numpy ndarrays for ease-of-use and
efficiency.
Lihang Li NLPR Getting Started With Linux and Python By Caffe
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Build Caffe From Scratch
Play With Caffe Examples
Caffe Interface - matcaffe
The MATLAB interface matcaffe is the caffe mex and its helper
m-files in caffe/matlab. Load models, do forward and backward,
extract output and read-only model weights, and load the
binaryproto 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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Outline
1 Goal
2 Linux Basics
Open Source
Hello World
Recommended Books
3 Fundamentals of Python
Why Python
A Byte of Python
Good References
4 Caffe
Build Caffe From Scratch
Play With Caffe Examples
5 Conclusion
6 What’s Next
Lihang Li NLPR Getting Started With Linux and Python By Caffe
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’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 to
be able to read the source code of Caffe Python samples and do
some simple hack.
Caffe
Through learning how to deploy Caffe on Linux by building from
source code, people should find it comfortable to deploy other
complicated software packages by reading the README or help
file shipped with the packages.
Lihang Li NLPR Getting Started With Linux and Python By Caffe
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
Outline
1 Goal
2 Linux Basics
Open Source
Hello World
Recommended Books
3 Fundamentals of Python
Why Python
A Byte of Python
Good References
4 Caffe
Build Caffe From Scratch
Play With Caffe Examples
5 Conclusion
6 What’s Next
Lihang Li NLPR Getting Started With Linux and Python By Caffe
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’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
Goal
Linux Basics
Fundamentals of Python
Caffe
Conclusion
What’s Next
The End
Thank You & Have Fun!
Lihang Li NLPR Getting Started With Linux and Python By Caffe

More Related Content

PPTX
Python Seminar PPT
PDF
Python final ppt
PDF
Python - the basics
PPTX
Python Tutorial Part 2
PPTX
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
PDF
Introduction to python
PDF
Beginning Python
PDF
Introduction To Python | Edureka
Python Seminar PPT
Python final ppt
Python - the basics
Python Tutorial Part 2
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
Introduction to python
Beginning Python
Introduction To Python | Edureka

What's hot (19)

PPT
Python ppt
PPT
Introduction to Python
PDF
Python for Science and Engineering: a presentation to A*STAR and the Singapor...
PPTX
GDG Helwan Introduction to python
PPTX
Introduction about Python by JanBask Training
PDF
Introduction to python 3 2nd round
PDF
Introduction to python 3
PPTX
Beginning Python Programming
PPTX
Python Programming Language
PPTX
Python Tutorial for Beginner
PDF
Python Foundation – A programmer's introduction to Python concepts & style
PPTX
Python Summer Internship
PDF
web programming Unit VIII complete about python by Bhavsingh Maloth
PPTX
Python Introduction | JNTUA | R19 | UNIT 1
PDF
Advanced Python Tutorial | Learn Advanced Python Concepts | Python Programmin...
PPTX
Python final presentation kirti ppt1
PPT
Intro to Python
PDF
Python Workshop
PPT
Why I Love Python
Python ppt
Introduction to Python
Python for Science and Engineering: a presentation to A*STAR and the Singapor...
GDG Helwan Introduction to python
Introduction about Python by JanBask Training
Introduction to python 3 2nd round
Introduction to python 3
Beginning Python Programming
Python Programming Language
Python Tutorial for Beginner
Python Foundation – A programmer's introduction to Python concepts & style
Python Summer Internship
web programming Unit VIII complete about python by Bhavsingh Maloth
Python Introduction | JNTUA | R19 | UNIT 1
Advanced Python Tutorial | Learn Advanced Python Concepts | Python Programmin...
Python final presentation kirti ppt1
Intro to Python
Python Workshop
Why I Love Python
Ad

Viewers also liked (11)

PPTX
DIY Deep Learning with Caffe Workshop
PPTX
Caffe framework tutorial
PPTX
Caffe framework tutorial2
PDF
Caffe - A deep learning framework (Ramin Fahimi)
PDF
Classifier evaluation and comparison
PDF
instruction of install Caffe on ubuntu
PPTX
Nurse schedule goal programming (Cyclical)
PDF
Face Recognition Based on Deep Learning (Yurii Pashchenko Technology Stream)
PPTX
Computer Vision, Deep Learning, OpenCV
PPTX
Object Recognition
PPT
CUDA & CAFFE
DIY Deep Learning with Caffe Workshop
Caffe framework tutorial
Caffe framework tutorial2
Caffe - A deep learning framework (Ramin Fahimi)
Classifier evaluation and comparison
instruction of install Caffe on ubuntu
Nurse schedule goal programming (Cyclical)
Face Recognition Based on Deep Learning (Yurii Pashchenko Technology Stream)
Computer Vision, Deep Learning, OpenCV
Object Recognition
CUDA & CAFFE
Ad

Similar to Getting started with Linux and Python by Caffe (20)

PDF
How to write a well-behaved Python command line application
PPTX
Linux Introduction , Unix vs Linux , Linux Advantages
PPTX
An Introduction To Python - Python, Print()
PDF
The Python Book_ The ultimate guide to coding with Python ( PDFDrive ).pdf
ODP
Intro To Linux
ODP
Learn python
PDF
Lecture1_cis4930.pdf
PPTX
Topic_2_Introduction_to_Unix.pptx
ODP
Introduction to linux
PDF
Linux Presentation_SSD.pdf
PDF
Getting started with python
PDF
QE-SSP - Lecture 2: Productivity tools: Linux & JupyterLab
PDF
Python: an introduction for PHP webdevelopers
PDF
GUIDE TO PROGRAMMING WITH PYTHON
PPTX
Python Programming Essentials - M2 - Introduction to Python
PDF
Python tutorial
PDF
Linux For Linguists
PDF
Linux For Linguists
PPT
Linux - Introductions to Linux Operating System
PDF
What is Python?
How to write a well-behaved Python command line application
Linux Introduction , Unix vs Linux , Linux Advantages
An Introduction To Python - Python, Print()
The Python Book_ The ultimate guide to coding with Python ( PDFDrive ).pdf
Intro To Linux
Learn python
Lecture1_cis4930.pdf
Topic_2_Introduction_to_Unix.pptx
Introduction to linux
Linux Presentation_SSD.pdf
Getting started with python
QE-SSP - Lecture 2: Productivity tools: Linux & JupyterLab
Python: an introduction for PHP webdevelopers
GUIDE TO PROGRAMMING WITH PYTHON
Python Programming Essentials - M2 - Introduction to Python
Python tutorial
Linux For Linguists
Linux For Linguists
Linux - Introductions to Linux Operating System
What is Python?

More from Lihang Li (8)

PPTX
Something about SSE and beyond
PDF
Some experiences and lessons learnt from hunting a job
PDF
Point cloud mesh-investigation_report-lihang
PDF
Rtabmap investigation report-lihang
PDF
Rgbdslam and mapping_investigation_report-lihang
PDF
DTAM: Dense Tracking and Mapping in Real-Time, Robot vision Group
PDF
2013新人见面会-中科院开源软件协会介绍-hustcalm
PDF
像Hackers一样写博客-hustcalm
Something about SSE and beyond
Some experiences and lessons learnt from hunting a job
Point cloud mesh-investigation_report-lihang
Rtabmap investigation report-lihang
Rgbdslam and mapping_investigation_report-lihang
DTAM: Dense Tracking and Mapping in Real-Time, Robot vision Group
2013新人见面会-中科院开源软件协会介绍-hustcalm
像Hackers一样写博客-hustcalm

Recently uploaded (20)

PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPTX
Lecture Notes Electrical Wiring System Components
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPT
Project quality management in manufacturing
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
Well-logging-methods_new................
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
Welding lecture in detail for understanding
PPTX
CH1 Production IntroductoryConcepts.pptx
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Foundation to blockchain - A guide to Blockchain Tech
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Lecture Notes Electrical Wiring System Components
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Project quality management in manufacturing
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Well-logging-methods_new................
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Automation-in-Manufacturing-Chapter-Introduction.pdf
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Model Code of Practice - Construction Work - 21102022 .pdf
Welding lecture in detail for understanding
CH1 Production IntroductoryConcepts.pptx
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx

Getting started with Linux and Python by Caffe

  • 1. 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
  • 2. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Outline 1 Goal 2 Linux Basics Open Source Hello World Recommended Books 3 Fundamentals of Python Why Python A Byte of Python Good References 4 Caffe Build Caffe From Scratch Play With Caffe Examples 5 Conclusion 6 What’s Next Lihang Li NLPR Getting Started With Linux and Python By Caffe
  • 3. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’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 Python code. Caffe Deploy Caffe on Linux by building from source code and learn the examples. Lihang Li NLPR Getting Started With Linux and Python By Caffe
  • 4. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Open Source Hello World Recommended Books Outline 1 Goal 2 Linux Basics Open Source Hello World Recommended Books 3 Fundamentals of Python Why Python A Byte of Python Good References 4 Caffe Build Caffe From Scratch Play With Caffe Examples 5 Conclusion 6 What’s Next Lihang Li NLPR Getting Started With Linux and Python By Caffe
  • 5. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Open Source Hello World Recommended 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 the concept, you should think of free as in free speech, not as in free beer. Lihang Li NLPR Getting Started With Linux and Python By Caffe
  • 6. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Open Source Hello World Recommended 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 to your needs (freedom 1). Access to the source code is a precondition for this. The freedom to redistribute copies so you can help your neighbor (freedom 2). The freedom to improve the program, and release your improvements to the public, so that the whole community benefits (freedom 3). Access to the source code is a precondition for this. Lihang Li NLPR Getting Started With Linux and Python By Caffe
  • 7. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Open Source Hello World Recommended Books GNU What is GNU? GNU is a Unix-like operating system. That means it is a collection of many programs: applications, libraries, developer tools, even games. The development of GNU, started in January 1984, is known as the GNU Project. Many of the programs in GNU are released under the auspices of the GNU Project; those we call GNU packages. The name GNU is a recursive acronym for GNU’s Not Unix. GNU is pronounced g’noo, as one syllable, like saying grew but replacing the r with n. Lihang Li NLPR Getting Started With Linux and Python By Caffe
  • 8. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Open Source Hello World Recommended Books Linux Linux or GNU/Linux? The program in a Unix-like system that allocates machine resources and talk to the hardware is called the kernel. GNU is typically used with a kernel called Linux. This combination is the GNU/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 Linux was started). Volunteers continue developing the Hurd because it is an interesting technical project. Without the GNU packages(gcc, make, etc), Linus would find it hard to start writing the Linux kernel. Lihang Li NLPR Getting Started With Linux and Python By Caffe
  • 9. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Open Source Hello World Recommended 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
  • 10. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Open Source Hello World Recommended 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
  • 11. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Open Source Hello World Recommended 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
  • 12. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Open Source Hello World Recommended 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
  • 13. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Why Python A Byte of Python Good References Outline 1 Goal 2 Linux Basics Open Source Hello World Recommended Books 3 Fundamentals of Python Why Python A Byte of Python Good References 4 Caffe Build Caffe From Scratch Play With Caffe Examples 5 Conclusion 6 What’s Next Lihang Li NLPR Getting Started With Linux and Python By Caffe
  • 14. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Why Python A Byte of Python Good References What is Python? Python Python is a great object-oriented, interpreted, and interactive programming language, comparable to Perl, Ruby, Scheme, or Java. Python Features Open Source and cross-platform(Linux, MacOS, Windows...) Uses an elegant syntax, making the programs you write easier to read. Data types are strongly and dynamically typed. Automatic memory management. Lihang Li NLPR Getting Started With Linux and Python By Caffe
  • 15. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Why Python A Byte of Python Good References Hello Python! #!/usr/bin/env python myString = "Hello Python!" print myString Run Python Interactive intepreter from the command line(Python or IPython) Running a script written in Python(python script name.py) Lihang Li NLPR Getting Started With Linux and Python By Caffe
  • 16. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Why Python A Byte of Python Good 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
  • 17. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Why Python A Byte of Python Good 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
  • 18. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Why Python A Byte of Python Good 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
  • 19. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Why Python A Byte of Python Good 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
  • 20. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Why Python A Byte of Python Good 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
  • 21. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Why Python A Byte of Python Good 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
  • 22. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Why Python A Byte of Python Good 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
  • 23. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Why Python A Byte of Python Good 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
  • 24. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Why Python A Byte of Python Good 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
  • 25. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Why Python A Byte of Python Good 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
  • 26. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Why Python A Byte of Python Good 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
  • 27. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Why Python A Byte of Python Good 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
  • 28. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Why Python A Byte of Python Good 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 from other modules using the import command. Packages are namespaces which contain multiple packages and modules themselves. They are simply directories, which MUST contain 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
  • 29. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Why Python A Byte of Python Good References Scientific Python SciPy SciPy(http://www.scipy.org/) is an open source library of scientific tools for Python. SciPy supplements the popular NumPy module, gathering a variety of high level science and engineering modules together as a single package. SciPy includes modules for linear algebra, optimization, integration, special functions, signal and 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 the successor to both Numeric and Numarray. Lihang Li NLPR Getting Started With Linux and Python By Caffe
  • 30. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Why Python A Byte of Python Good 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
  • 31. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Build Caffe From Scratch Play With Caffe Examples Outline 1 Goal 2 Linux Basics Open Source Hello World Recommended Books 3 Fundamentals of Python Why Python A Byte of Python Good References 4 Caffe Build Caffe From Scratch Play With Caffe Examples 5 Conclusion 6 What’s Next Lihang Li NLPR Getting Started With Linux and Python By Caffe
  • 32. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Build Caffe From Scratch Play 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 Jia during his PhD at UC Berkeley, and is in active development by the Berkeley Vision and Learning Center (BVLC) and by community contributors. Caffe is released under the BSD 2-Clause license. With Caffe, you can do whatever Deep Learning can do easily! Lihang Li NLPR Getting Started With Linux and Python By Caffe
  • 33. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Build Caffe From Scratch Play With Caffe Examples Why use Caffe? Clean architecture enables rapid deployment. Readable & modifiable implementation fosters active development. Speed makes Caffe perfect for industry use. Caffe can process over 40M images per day with a single NVIDIA K40 or Titan GPU*. Thats 5 ms/image in training, and 2 ms/image in test. We believe that Caffe is the fastest CNN implementation available. Community: Caffe already powers academic research projects, startup prototypes, and even large-scale industrial applications in vision, speech, and multimedia. There is an active discussion and support community on Github. Lihang Li NLPR Getting Started With Linux and Python By Caffe
  • 34. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Build Caffe From Scratch Play 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
  • 35. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Build Caffe From Scratch Play 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
  • 36. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Build Caffe From Scratch Play 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
  • 37. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Build Caffe From Scratch Play 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 as sudo 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
  • 38. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Build Caffe From Scratch Play 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
  • 39. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Build Caffe From Scratch Play 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
  • 40. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Build Caffe From Scratch Play 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
  • 41. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Build Caffe From Scratch Play 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
  • 42. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Build Caffe From Scratch Play 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
  • 43. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Build Caffe From Scratch Play 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
  • 44. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Build Caffe From Scratch Play 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
  • 45. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Build Caffe From Scratch Play 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
  • 46. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Build Caffe From Scratch Play 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
  • 47. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Build Caffe From Scratch Play 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
  • 48. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Build Caffe From Scratch Play 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
  • 49. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Build Caffe From Scratch Play 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
  • 50. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Build Caffe From Scratch Play 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
  • 51. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Build Caffe From Scratch Play 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
  • 52. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Build Caffe From Scratch Play With Caffe Examples Caffe Usage Interfaces Caffe has command line, Python, and MATLAB interfaces for day-to-day usage, interfacing with research code, and rapid prototyping. While Caffe is a C++ library at heart and it exposes a modular interface for development, not every occasion calls for custom compilation. The cmdcaffe, pycaffe, and matcaffe interfaces are here for you. Lihang Li NLPR Getting Started With Linux and Python By Caffe
  • 53. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Build Caffe From Scratch Play With Caffe Examples Caffe Interface - cmdcaffe cmdcaffe The command line interface cmdcaffe is the caffe tool for model training, scoring, and diagnostics. Run caffe without any arguments for help. This tool and others are found in caffe/build/tools. Lihang Li NLPR Getting Started With Linux and Python By Caffe
  • 54. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Build Caffe From Scratch Play With Caffe Examples cmdcaffe - Training caffe train learns models from scratch, resumes learning from saved snapshots, and fine-tunes models to new data and tasks. All training requires a solver configuration through the -solver solver.prototxt argument. Resuming requires the -snapshot model 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
  • 55. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Build Caffe From Scratch Play With Caffe Examples cmdcaffe - Testing caffe test scores models by running them in the test phase and reports the net output as its score. The net architecture must be properly defined to output an accuracy measure or loss as its output. The per-batch score is reported and then the grand average 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
  • 56. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Build Caffe From Scratch Play With Caffe Examples cmdcaffe - Benchmarking caffe time benchmarks model execution layer-by-layer through timing and synchronization. This is useful to check system performance 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
  • 57. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Build Caffe From Scratch Play With Caffe Examples cmdcaffe - Diagnostics caffe device query reports GPU details for reference and checking device ordinals for running on a given device in multi-GPU machines. # query the first device caffe device_query -gpu 0 Lihang Li NLPR Getting Started With Linux and Python By Caffe
  • 58. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Build Caffe From Scratch Play With Caffe Examples Caffe Interface - pycaffe pycaffe The Python interface pycaffe is the caffe module and its scripts in caffe/python. import caffe to load models, do forward and backward, handle IO, visualize networks, and even instrument model solving. All model data, derivatives, and parameters are exposed for reading and writing. Compile pycaffe by make pycaffe. The module dir caffe/python/caffe should be installed in your PYTHONPATH for import caffe. Lihang Li NLPR Getting Started With Linux and Python By Caffe
  • 59. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Build Caffe From Scratch Play With Caffe Examples pycaffe caffe.Net is the central interface for loading, configuring, and running models. caffe.Classsifier and caffe.Detector provide convenience interfaces for common tasks. caffe.SGDSolver exposes the solving interface. caffe.io handles input/output with preprocessing and protocol buffers. caffe.draw visualizes network architectures. Caffe blobs are exposed as numpy ndarrays for ease-of-use and efficiency. Lihang Li NLPR Getting Started With Linux and Python By Caffe
  • 60. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Build Caffe From Scratch Play With Caffe Examples Caffe Interface - matcaffe The MATLAB interface matcaffe is the caffe mex and its helper m-files in caffe/matlab. Load models, do forward and backward, extract output and read-only model weights, and load the binaryproto 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
  • 61. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Outline 1 Goal 2 Linux Basics Open Source Hello World Recommended Books 3 Fundamentals of Python Why Python A Byte of Python Good References 4 Caffe Build Caffe From Scratch Play With Caffe Examples 5 Conclusion 6 What’s Next Lihang Li NLPR Getting Started With Linux and Python By Caffe
  • 62. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’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 to be able to read the source code of Caffe Python samples and do some simple hack. Caffe Through learning how to deploy Caffe on Linux by building from source code, people should find it comfortable to deploy other complicated software packages by reading the README or help file shipped with the packages. Lihang Li NLPR Getting Started With Linux and Python By Caffe
  • 63. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next Outline 1 Goal 2 Linux Basics Open Source Hello World Recommended Books 3 Fundamentals of Python Why Python A Byte of Python Good References 4 Caffe Build Caffe From Scratch Play With Caffe Examples 5 Conclusion 6 What’s Next Lihang Li NLPR Getting Started With Linux and Python By Caffe
  • 64. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’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
  • 65. Goal Linux Basics Fundamentals of Python Caffe Conclusion What’s Next The End Thank You & Have Fun! Lihang Li NLPR Getting Started With Linux and Python By Caffe