caffe Custom Python Layers Prototxt Template


Ok, so now you have your layer designed! This is how you define it in your .prototxt file:

layer {
  name: "LayerName"
  type: "Python"
  top: "TopBlobName"
  bottom: "BottomBlobName"
  python_param {
    module: "My_Custom_Layer_File"
    layer: "My_Custom_Layer_Class"
    param_str: '{"param1": 1,"param2":True, "param3":"some string"}'
        phase: TRAIN

Important remarks:

  • type must be Python;
  • You must have a python_param dictionary with at least the module and layer parameters;
  • module refers to the file where you implemented your layer (without the .py);
  • layer refers to the name of your class;
  • You can pass parameters to the layer using param_str (more on accessing them bellow);
  • Just like any other layer, you can define in which phase you want it to be active (see the examples to see how you can check the current phase);