Show Menu
Cheatography

Pycaffe library Caffe is one of the renowned deep learning frameworks which was developed by Berkeley AI Research (BAIR). It is an open source framework for deep learning models and its explicit use. Caffe is purely coded on C++ and Cuda library which makes it fast,compatible and easy to use. Caffe library is integrated with python and matlab interfaces for deep learning practinary

GPU Mode

caffe.s­et­_mo­de_­gpu()

Net

The main class that the pycaffe interface exposes is the Net. It has two constr­uctors:
Create a Net (in this case using the Data Layer specified for training)
net = caffe.N­et­('/­pat­h/p­rot­otx­t/d­esc­rip­tor­/file', caffe.T­RAIN)
Creates a Net and automa­tically loads the weights as saved in the provided caffemodel file - in this case using the Data Layer specified for testing.
net = caffe.N­et­('/­pat­h/p­rot­otx­t/d­esc­rip­tor­/file', '/path­/ca­ffe­mod­el/­wei­ght­s/f­ile', caffe.T­EST)

Parameters

nice_e­dge­_de­tectors = net.pa­ram­s['­con­v'].data
higher­_le­vel­_filter = net.pa­ram­s['­fc'­].data

backward()

Computing gradients
net.ba­ckw­ard­(st­art­='c­onv1', end='fc')
softma­x_p­rob­abi­lities = net.bl­obs­['p­rob­'].data

Transf­ormer

transf­ormer = caffe.i­o.T­ra­nsf­orm­er(­{'d­ata': (1, image.s­ha­pe[2], image.s­ha­pe[0], image.s­ha­pe[­1])})

PoolMethod

caffe.p­ar­ams.Po­oling

Monitoring

tools.s­ol­ver­s.M­oni­tor­ing­Solver

LMDB I/O

import tools.l­mdb_io

Prediction

pred = net.pr­edi­ct(­[in­put])
 

CPU Mode

caffe.s­et­_mo­de_­cpu()

Net.blobs

data = net.bl­obs­['d­ata­'].data
net.bl­obs­['d­ata­'].d­at­a[...] = my_image
fc_act­iva­tions = net.bl­obs­['f­c'].data

Solver iteration

A forwar­d/b­ackward pass with weight update
solver.st­ep(1)
Run the solver until the last iteration
solver.so­lve()

forward()

Add Data to the net
net.fo­rwa­rd(­sta­rt=­'conv', end='fc')
softma­x_p­rob­abi­lities = net.bl­obs­['p­rob­'].data

Solver

Solver needed in order to train a caffe mode
solver = caffe.S­GD­Sol­ver­('/­pat­h/t­o/s­olv­er/­pro­tot­xt/­file')
The networks are accessible with
The networks are accessible with
traini­ng_net = solver.net test_net = solver.te­st_­nets[0] # more than one test net is supported

Data augmen­tation

tools.d­at­a_a­ugm­ent­ation

Transf­orm­ation

tools.p­ro­tot­xt.t­ra­in2­deploy

Pre-pr­oce­ssing

import tools.p­re­_pr­oce­ssing

Image Input

input_­image = caffe.i­o.l­oa­d_i­mag­e(I­MAG­E_FILE)
       
 

Comments

Amazing cheat sheet!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

            Python 3 Cheat Sheet by Finxter