我感兴趣的是为zf复制prototxt文件中的步骤。我不确定的部分是softmax层。rpn_cls_score的维度(1,18,h,w)在这里创建:
layer {
name: "rpn_cls_score"
type: "Convolution"
bottom: "rpn/output"
top: "rpn_cls_score"
convolution_param {
num_output: 18 # 2(bg/fg) * 9(anchors)
kernel_size: 1 pad: 0 stride: 1
weight_filler { type: "gaussian" std: 0.01 }
bias_filler { type: "constant" value: 0 }
}
}然后在这里将其重塑为维数(1,2,9*h,w):
layer {
bottom: "rpn_cls_score"
top: "rpn_cls_score_reshape"
name: "rpn_cls_score_reshape"
type: "Reshape"
reshape_param { shape { dim: 0 dim: 2 dim: -1 dim: 0 } }
}最后,它被传递给softmax:
layer {
name: "rpn_cls_prob"
type: "Softmax"
bottom: "rpn_cls_score_reshape"
top: "rpn_cls_prob"
}我的问题是这个。根据caffe在线文档,softmax需要一个一维输入,但是rpn_cls_score_reshape有维度(1,2,9*h,w)。是所有索引上的softmax和,还是它选择了一个规范轴,并且只在其余的索引上求和(就像C++代码所指出的那样)?在这种情况下,这意味着它将rpn_cls_score_reshape划分为两个数组,(1,channel=1,9*h,w)和(1,channel=2,9*h,w),一个用于第二个索引的每个值,在每个数组中执行softmax,方法是将9*h*w组件的指数相加,然后将它们重新组合成一个具有原始维度(1,2,9*h,w)的数组,并将其返回为rpn_cls_prob。如果不是,softmax如何处理多个维度的输入数组?
谢谢..
发布于 2017-10-15 10:06:33
正如SofmaxParameter在caffe.proto中所描述的那样,它有一个参数轴,默认设置为1:
// The axis along which to perform the softmax -- may be negative to index
// from the end (e.g., -1 for the last axis).
// Any other axes will be evaluated as independent softmaxes.
optional int32 axis = 2 [default = 1];因此,您对C++实现的理解是正确的,关于softmax如何处理N>1的ND输入的问题是,每个轴分别进行评估。
至于更快的-RCNN,如果您只对前景框感兴趣,您只需拆分rpn_cls_score blob并只使用它的下半部分(即在培训您的网络集num_output: 9 # instead of 18之后,或者在培训期间使用Slice层只取下半部分)。注意相应的改变模式,以防你像往常一样训练,在训练后改变num_output。
https://stackoverflow.com/questions/46733055
复制相似问题