Caffe 层中的层

Layers within a layer in Caffe

我有一个自己编写的自定义损失层,该层将 softmaxsigmoid 激活应用于底部 [0] blob 的一部分。

Ex: `bottom[0]` is of shape (say): `[20, 7, 7, 50]` (`NHWC` format)
I would like to apply `softmax` to `[20, 7, 7, 25]` (first 25 channels) and 
`sigmoid` to `[20, 7, 7, 1]` (just one channel) and the remaining 24 channels are taken in as it is.

如何有效地为这两个 softmaxsigmoid 层的输入 blob 分配内存并释放这些内存?

所有中间激活以及网络的输入和输出 blob 都由网络 class 管理并在 src/caffe/net.cppNet<Dtype>::Init 函数中设置。

您不需要allocate/deallocate层本身内部的顶部和底部 blob 内存。

无需在内部分配数据,您只需在外部使用 "Slice" 层并使用 caffe "off-the-shelf" 层对输入 blob 进行切片:

layer {
  name: "slice"
  type: "Slice"
  bottom: "input_to_loss"
  top: "to_softmax"
  top: "to_sigmoid"
  top: "leftovers"
  slice_param { 
    axis: -1  # slice the last axis
    slice_point: 25
    slice_point: 26
  }
}