caffe: model definition: write same layer with different phase using caffe.NetSpec()

I assume you mean how to define phase when writing a prototxt using caffe.NetSpec? from caffe import layers as L, params as P, to_proto import caffe ns = caffe.NetSpec() ns.data = L.Data(name=”data”, data_param={‘source’:’/path/to/lmdb’,’batch_size’:32}, include={‘phase’:caffe.TEST}) If you want to have BOTH train and test layers in the same prototxt, what I usually do is making one … Read more

How to reduce a fully-connected (`”InnerProduct”`) layer using truncated SVD

Some linear-algebra background Singular Value Decomposition (SVD) is a decomposition of any matrix W into three matrices: W = U S V* Where U and V are ortho-normal matrices, and S is diagonal with elements in decreasing magnitude on the diagonal. One of the interesting properties of SVD is that it allows to easily approximate … Read more

How to create caffe.deploy from train.prototxt

There are two main differences between a “train” prototxt and a “deploy” one: 1. Inputs: While for training data is fixed to a pre-processed training dataset (lmdb/HDF5 etc.), deploying the net require it to process other inputs in a more “random” fashion. Therefore, the first change is to remove the input layers (layers that push … Read more

Fine Tuning of GoogLeNet Model

Assuming you are trying to do image classification. These should be the steps for finetuning a model: 1. Classification layer The original classification layer “loss3/classifier” outputs predictions for 1000 classes (it’s mum_output is set to 1000). You’ll need to replace it with a new layer with appropriate num_output. Replacing the classification layer: Change layer’s name … Read more

caffe data layer example step by step

You can use a “Python” layer: a layer implemented in python to feed data into your net. (See an example for adding a type: “Python” layer here). import sys, os sys.path.insert(0, os.environ[‘CAFFE_ROOT’]+’/python’) import caffe class myInputLayer(caffe.Layer): def setup(self,bottom,top): # read parameters from `self.param_str` … def reshape(self,bottom,top): # no “bottom”s for input layer if len(bottom)>0: raise … Read more