neural-networkdeep-learningcaffeconv-neural-networkpycaffe

caffe: convolution with a fix predifined kernel (filter)


Instead of having a learnable filter, I am interested in a convolution with a fix predefined matrix; for example sobel filter:

enter image description here

so, I set learning = 0 (so its fixed), and my kernel size = 3 as:

layer {
    name: "conv1"
    type: "Convolution"
    bottom: "data"
    top: "conv1"
    param { lr_mult: 0 decay_mult: 0 }
    convolution_param {
      num_output: 10
      kernel_size: 3    # filter is 3x3
      stride: 2          
      weight_filler {
        type: ??}
    }
  }

Now, I do not know how to give matrix information to the conv layer. Any ideas? I think it should go to weight_filler, but how?

One more question: num_output has to be same as bottom's (data channel = 10 here) channel size? can I set num_output another number? if yes, what will happen and what that means?


Solution

  • How to init weights to specific values?

    You can use net_surgery to load your untrained/un-initialized net in python and then assign the specific weights you want to the filters, save the net, and use it with the weights you want for this specific layer.

    How do set num_output and other conv_params?

    This is a good question: You have an input blob of shape bx10xhxw and you want to apply a 3x3 filter to each channel and get back a new filtered bx10xhxw. If you just set num_output: 10, the shape of the filters would be 10x10x3x3, that is, 10 filters of shape 10x3x3 - which is not want you expect. You want a 3x3 filter.
    To that end you need to look at group conv_param. Setting group: 10 together with num_output: 10 (assuming input c=10) will give you what you want, the weight shape will be 10x1x3x3.