Machine learning 如何在Caffe中为二进制分类器获取两个输出值(针对两个类中的每个类)?

Machine learning 如何在Caffe中为二进制分类器获取两个输出值(针对两个类中的每个类)?,machine-learning,computer-vision,neural-network,deep-learning,caffe,Machine Learning,Computer Vision,Neural Network,Deep Learning,Caffe,我正在用LeNet网络作为二元分类器进行实验(是,否)。 用于测试的配置文件中的第一层和最后几层如下所示: layer { name: "data" type: "ImageData" top: "data" top: "label" include { phase: TEST } transform_param { scale: 0.00390625 }

我正在用LeNet网络作为二元分类器进行实验(是,否)。 用于测试的配置文件中的第一层和最后几层如下所示:

    layer {
      name: "data"
      type: "ImageData"
      top: "data"
      top: "label"
      include {
        phase: TEST
      }
      transform_param {
        scale: 0.00390625
      }
      image_data_param {
        source: "examples/my_example/test_images_labels.txt"
        batch_size: 1
        new_height: 128
        new_width: 128
      }
    }
...
    layer {
      name: "ip2"
      type: "InnerProduct"
      bottom: "ip1"
      top: "ip2"
      param {
        lr_mult: 1
      }
      param {
        lr_mult: 2
      }
      inner_product_param {
        num_output: 2
        weight_filler {
          type: "xavier"
        }
        bias_filler {
          type: "constant"
        }
      }
    }
    layer {
      name: "accuracy"
      type: "Accuracy"
      bottom: "ip2"
      bottom: "label"
      top: "accuracy"
    }
    layer {
      name: "loss"
      type: "SoftmaxWithLoss"
      bottom: "ip2"
      bottom: "label"
      top: "loss"
    }
对于测试,我将batch_size设置为1,因此我使用以下命令运行测试:

./build/tools/caffe test -model examples/my_example/lenet_test.prototxt -weights=examples/my_example/lenet_iter_528.caffemodel -iterations 200
我的目的是能够分别分析每个测试图像的结果。 目前,我获得了每个迭代的以下信息:

但是,由于我的网络中有两个输出,在测试时,我希望看到每个输出有两个单独的值:一个用于类“0”(“否”),另一个用于类“1”(“是”)。应该是这样的:

我应该如何修改测试配置文件以实现它?

您希望看到
“Softmax”
概率输出(而不仅仅是丢失)。
为此,您可以尝试使用带有两个
“top”
“SoftmaxWithLoss”
(我不能100%确定此选项是否完全可用/受支持):


或者,如果前一种解决方案不起作用,则显式添加一个
“Softmax”
层:

layer {
  name: "prob"
  type: "Softmax"
  bottom: "ip2"
  top: "prob"
}

第一个解决方案不起作用,尽管第二个解决方案起作用。非常感谢@您能否更具体地说明第一个解决方案不起作用的原因?Shai,出现了一个错误,显示无法指定两个最大值。@evaluate OK。我想这项功能还没有被合并请不要编辑问题来询问新问题。发布一个新问题。如果你认为它们是相关的,你可以为上下文添加一个链接。此外,如果“上述问题已经解决”,你为什么不点击旁边的“v”图标来“接受”答案?为什么你声称“有时它是另外做的(首先是类1,然后是类0)”?这似乎是一个错误。你确定吗?你能复制它吗?如果是这样,您可能希望在BVLC/caffe github页面中报告此错误。
Batch 41, class 0 output: 0.755
Batch 41, class 1 output: 0.201
layer {
  name: "loss"
  type: "SoftmaxWithLoss"
  bottom: "ip2"
  bottom: "label"
  top: "loss"
  top: "prob" # add class probability output
}
layer {
  name: "prob"
  type: "Softmax"
  bottom: "ip2"
  top: "prob"
}