How to set the bias_term false in a convolutional layer pycaffe?

1k views Asked by At

I am using pycaffe to create my net and I want to set the bias term in a convolutional layer to false, but can not find anything how to do so. My code-snippet so far:

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

n.conv1 = L.Convolution(n.data,kernel_size = 3,stride = 1,num_output=16,pad=1,weight_filler=dict(type='xavier'))
1

There are 1 answers

2
hbaderts On BEST ANSWER

As you already mention, this is done by setting the bias_term parameter to false. In general, you can find most layers and their parameters documented in the Layer Catalogue. You can set any parameter from PyCaffe by simply using the documented names and values from the Layer catalogue. Just remember, that you have to use correct Python syntax, i.e. False and not false!

n.conv1 = L.Convolution(n.data,
                        kernel_size=3,
                        stride=1,
                        num_output=16,
                        pad=1,
                        weight_filler=dict(type='xavier'),
                        bias_term=False
                        )

This will create the following entry in the .prototxt file:

layer {
  name: "conv1"
  type: "Convolution"
  bottom: "data"
  top: "conv1"
  convolution_param {
    num_output: 16
    bias_term: false
    pad: 1
    kernel_size: 3
    stride: 1
    weight_filler {
      type: "xavier"
    }
  }
}

As you can see, the option is recognized correctly and put inside the convolution_param block.