Caffe:如何获取 Python 层的相位? [英] Caffe: how to get the phase of a Python layer?
问题描述
我在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 TRAIN
ing 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 Users" google group 上发布了这个问题.如果那里有任何东西,我会更新.
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/de8ac324b42f20400000一个>
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屋!