Including `phase` and `blob_lr` in net prototxt from Python

69 views
Skip to first unread message

Marc

unread,
Mar 23, 2016, 4:37:14 PM3/23/16
to Caffe Users
This code:

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

def lenet(lmdb, batch_size):
   
# our version of LeNet: a series of linear and simple nonlinear transformations
    n
= caffe.NetSpec()
    n
.data, n.label = L.Data(batch_size=batch_size, backend=P.Data.LMDB, source=lmdb,
                             transform_param
=dict(scale=1./255), ntop=2)
    n
.conv1 = L.Convolution(n.data, kernel_size=5, num_output=20, weight_filler=dict(type='xavier'))
    n
.pool1 = L.Pooling(n.conv1, kernel_size=2, stride=2, pool=P.Pooling.MAX)
   
return n.to_proto()


with open('examples/mnist/lenet_auto_train.prototxt', 'w') as f:
    f
.write(str(lenet('examples/mnist/mnist_train_lmdb', 64)))


with open('examples/mnist/lenet_auto_test.prototxt', 'w') as f:
    f
.write(str(lenet('examples/mnist/mnist_test_lmdb', 100)))

produces a prototxt like this:
layer {
  name
: "data"
  type
: "Data"
  top
: "data"
  top
: "label"
  transform_param
{
    scale
: 0.00392156862745
 
}
  data_param
{
    source
: "examples/mnist/mnist_train_lmdb"
    batch_size
: 64
    backend
: LMDB
 
}
}
layer
{
  name
: "conv1"
  type
: "Convolution"
  bottom
: "data"
  top
: "conv1"
  convolution_param
{
    num_output
: 20
    kernel_size
: 5
    weight_filler
{
      type
: "xavier"
   
}
 
}
}
layer
{
  name
: "pool1"
  type
: "Pooling"
  bottom
: "conv1"
  top
: "pool1"
  pooling_param
{
    pool
: MAX
    kernel_size
: 2
    stride
: 2
 
}
}

but how can I specify something like:

layer {
  name
: "conv1"
  type
: "Convolution"
  bottom
: "data"
  top
: "conv1"
  convolution_param
{
    num_output
: 20
    kernel_size
: 5
    weight_filler
{
      type
: "xavier"
   
}
 
}
  blob_lr
: 0
  include
{
    phase
: "train"
 
}
}

where I'm specifying a blob-specific learning rate or which phase to include a layer on? I don't see any clear definition of the Layer().Convolution function anywhere in net_spec.py. How do I know what parameters are valid? I've tried trial-and-error guessing, but blob_lr=0 is not a valid keyword parameter.

Reply all
Reply to author
Forward
0 new messages