Caffe SigmoidCrossEntropyLoss 层多标签分类 c++

Pok*_*oke 2 c++ neural-network deep-learning caffe conv-neural-network

我有一个获取 2 个输入图像的网络,这两个图像属于 9 个类别中的一个以上类别。我见过的所有示例 - 在 Caffe 文档中 - 直接从 prototxt 加载输入图像,但是我通过我的 C++ 代码输入信息。

我的输入层如下所示

input: "data"
input_shape{dim:20 dim:6 dim:100 dim:100}

input: "class_label"
input_shape{dim:20 dim:9}
Run Code Online (Sandbox Code Playgroud)

损失层如下所示

layer {
  name: "classes"
  type: "InnerProduct"
  bottom: "ip2"
  top: "classes"
  param { lr_mult: 1 }
  param { lr_mult: 2 }
  inner_product_param {
    num_output: 9
    weight_filler {  type: "xavier" }
    bias_filler { type: "constant" }
  }
}


layer {
  name: "class_loss"
  type: "SigmoidCrossEntropyLoss"
  bottom: "classes"
  bottom: "class_label"
  top: "class_loss"
}
Run Code Online (Sandbox Code Playgroud)

我的假设是输入应该是一个看起来像这样的流 [0 0 1 0 1 0 1 0 0],其中 1 表示图像属于该类,0 表示它不属于该类,这是真的吗?

我的第二个问题是,我应该对 SigmoidCrossEntropyLoss 层的输出(例如 SoftmaxWithLoss 输出概率)有什么期望?

Sha*_*hai 5

  1. 你是对的:你的情况下的标签应该是一个二进制 9 向量。

  2. 损失层的输出是一个标量损失值。当您训练网络时,您应该预期该值会降低。对于预测(测试时间),您应该用简单的 sigmoid 层替换 sigmoid 损失层。一些 sigmoid 层的输出是一个 9 向量,每个条目代表相应类存在的概率。
    中的输出层deploy.prototxt应如下所示:

    layer {
      type: "Sigmoid"
      name: "class_prob"
      bottom: "classes"
      top: "class_prob"
    }
    
    Run Code Online (Sandbox Code Playgroud)