Caffe:如何获得Python层的相位? [英] Caffe: how to get the phase of a Python layer?

查看:84
本文介绍了Caffe:如何获得Python层的相位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在caffe中创建了一个"Python""myLayer",并将其用于网络train_val.prototxt中,我这样插入该层:

I created a "Python" layer "myLayer" in caffe, and use it in the net train_val.prototxt I insert the layer like this:

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!
}

现在,我的图层仅参与网络的TRAIN ing阶段,
我怎么知道在我图层的setup函数中?

Now, my layer only participates in the TRAINing phase of the net,
how can I know that in my layer's setup function??

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

PS,
我也在"Caffe用户" google组上发布了这个问题.如果有什么东西出现,我会udpdate.

PS,
I posted this question on "Caffe Users" google group as well. I'll udpdate if anything pops there.

推荐答案

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

This is a very good workaround, but if you are only interested in passing the phase as a parameter, now you can access the phase as an attribute of the layer. This feature was merged just 6 days ago https://github.com/BVLC/caffe/pull/3995.

特定的提交: https://github.com/BVLC/caffe/commit/de8ac32a02f3e324b0495f1729bff2446 a>

Specific commit: https://github.com/BVLC/caffe/commit/de8ac32a02f3e324b0495f1729bff2446d402c2c

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

With this new feature you just need to use the attribute self.phase. For example you can do the following:

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层的相位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆