gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 18:26:20 25 4
gpt4 key购买 nike

我在caffe中创建了一个"Python""myLayer",并在网络中使用它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 阶段,
我怎么知道我层的 setup 函数??

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

附言,
我在 "Caffe Users" google group 上发布了这个问题以及。如果那里弹出任何内容,我会更新。

最佳答案

正如 galloguille 指出的那样,caffe 现在将 phase 暴露给 python 层类。这个新功能使这个答案有点多余。了解 caffe python 层中的 param_str 对于将其他参数传递给该层仍然很有用。

原答案:

据我所知,没有简单的方法可以获取相位。但是,可以将任意参数从 net prototxt 传递给 python。这可以使用 python_paramparam_str 参数来完成。
这是如何完成的:

layer {
type: "Python"
...
python_param {
...
param_str: '{"phase":"TRAIN","numeric_arg":5}' # passing params as a STRING

在python中,你在层的setup函数中得到param_str:

import caffe, json
class myLayer(caffe.Layer):
def setup(self, bottom, top):
param = json.loads( self.param_str ) # use JSON to convert string to dict
self.phase = param['phase']
self.other_param = int( param['numeric_arg'] ) # I might want to use this as well...

关于python - Caffe:如何获得 Python 层的阶段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34549743/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com