5

I am modifying a Caffe tutorial to implement a neural network, but I am struggling to identify where some of the pycaffe modules are location in order to see certain function definitions.

For example, the tutorial mentions:

import caffe
from caffe import layers a L, params as P
....
L.Convolution(bottom, kernel_size=ks, stride=stride, num_output=nout, pad=pad, group=group)
L.InnerProduct(bottom, num_output=nout)
L.ReLU(fc, in_place=True)
...

Where can I find these function definitions and where can I see what other types of layers are pre-defined? I see that layers and params are defined here but there's no mention of the types (e.g. layers.Convolution, etc).

The reason I am trying to figure this out is because there are other prototxt parameters left out of the pycaffe tutorials that I would like to be able to define from Python when generating the prototxts. These include, blob_lr and include{phase: TRAIN}.

Shai
  • 111,146
  • 38
  • 238
  • 371
marcman
  • 3,233
  • 4
  • 36
  • 71

1 Answers1

7

You can add the blob_lr and phase like this:

import caffe
from caffe import layers a L, params as P

ns = caffe.NetSpec()
ns.conv = L.Convolution(bottom, convolution_param={'kernel_size':ks,
                                                   'stride':stride,
                                                   'num_output':nout, 
                                                   'pad':pad, 
                                                   'group':group},
                                param=[{'lr_mult':1, 'decay_mult':1},
                                       {'lr_mult':2, 'decay_mult':0}],
                                include={'phase': caffe.TRAIN})

You can see some more examples in this answer.

Community
  • 1
  • 1
Shai
  • 111,146
  • 38
  • 238
  • 371
  • Is this new syntax? A lot of this is different than the tutorial provided by the Caffe developers. For instance, putting all of that info into a `convolution_param` dict – marcman Mar 31 '16 at 16:30
  • @marcman I don't think it's new, it's a slightly different way of providing the parameters. I find it more clear this way. It's definitely easier this way to provide parameters that are of "repeated" type (e.g., the blob param `'lr_mult'`). – Shai Mar 31 '16 at 16:32
  • @Shai how can we specify the blob names and layer names seperately? – Gaurav Gupta Jun 17 '16 at 06:35
  • @gauravgupta you have an optional `name` argument – Shai Jun 17 '16 at 06:48