Caffe:如何获得Python层的阶段?

我在caffe中创建了一个“Python”图层“myLayer”,并在net train_val.prototxt中使用它我插入这样的图层:

layer {
  name: "my_py_layer"
  type: "Python"
  bottom: "in"
  top: "out"
  python_param {
    module: "my_module_name"
    layer: "myLayer"
  }
  include { phase: TRAIN } # THIS IS THE TRICKY PART!
}

现在,我的图层只参与网络的TRAINing阶段,
我怎么知道在我的图层的设置功能?

class myLayer(caffe.Layer):
  def setup(self, bottom, top):
     # I want to know here what is the phase?!!
  ...

PS,
我也在“Caffe Users” google group上发布了这个问题.如果有什么东西在那里,我会更新.

解决方法:

这是一个非常好的解决方法,但如果您只想将阶段作为参数传递,那么现在您可以访问阶段作为图层的属性.此功能刚刚在6天前合并https://github.com/BVLC/caffe/pull/3995.

具体承诺:https://github.com/BVLC/caffe/commit/de8ac32a02f3e324b0495f1729bff2446d402c2c

使用此新功能,您只需使用属性self.phase.例如,您可以执行以下操作:

class PhaseLayer(caffe.Layer):
"""A layer for checking attribute `phase`"""

def setup(self, bottom, top):
    pass

def reshape(self, bootom, top):
    top[0].reshape()

def forward(self, bottom, top):
    top[0].data[()] = self.phase
上一篇:Caffe相关库的介绍


下一篇:python – TensorFlow中卷积的自定义填充