【问题标题】:Caffe: Print the softmax scoreCaffe:打印softmax分数
【发布时间】:2017-06-16 07:57:12
【问题描述】:

在 Caffe 安装中给出的 MNIST 示例中。

对于任何给定的测试图像,如何获取每个类别的 softmax 分数并对其进行一些处理?说计算它们的均值和方差。

我是新手,所以一个细节会对我有很大帮助。我能够训练模型并使用测试功能来获得预测,但我不确定要编辑哪些文件才能获得上述结果。

【问题讨论】:

  • 你的python技能怎么样?
  • 我会说至少是本科水平。
  • 然后使用 Python 接口和 deploy.prototxt,你可以对输出做任何你想做的事情
  • @Shai 你能举个例子吗?

标签: deep-learning caffe


【解决方案1】:

可以使用python接口

import caffe
net = caffe.Net('/path/to/deploy.prototxt', '/path/to/weights.caffemodel', caffe.TEST)
in_ = read_data(...) # this is up to you to read a sample and convert it to numpy array
out_ = net.forward(data=in_) # assuming your net expects "data" in blob

现在您的网络输出在字典 out 中(键是输出 blob 的名称)。您可以在几个示例等上循环运行它。

【讨论】:

    【解决方案2】:

    我可以试着回答你的问题。假设在您的部署网络中,softmax 层如下所示:

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

    在你处理数据的python代码中,结合@Shai提供的代码,可以在@Shai的代码基础上添加代码,得到每个类别的概率:

    predicted_prob = net.blobs['prob'].data
    

    predicted_prob 将返回一个数组,其中包含所有类别的概率。

    例如,如果您只有两个类别,predicted_prob[0][0] 将是此测试数据属于一个类别的概率,predicted_prob[0][1] 将是另一个类别的概率。

    PS:

    如果你不想写任何额外的python脚本,根据https://github.com/BVLC/caffe/tree/master/examples/mnist 它说这个例子将每 500 次迭代自动进行一次测试。 “500”在solver中定义,如https://github.com/BVLC/caffe/blob/master/examples/mnist/lenet_solver.prototxt

    所以你需要追溯处理求解器文件的 caffe 源代码。我想应该是https://github.com/BVLC/caffe/blob/master/src/caffe/solver.cpp

    我不确定solver.cpp 是否是您需要查看的正确文件。但在这个文件中,你可以看到它具有测试和计算某些值的功能。如果没有其他人可以回答您的问题,我希望它可以给您一些想法。

    【讨论】:

      猜你喜欢
      • 2016-02-10
      • 1970-01-01
      • 2019-01-10
      • 2017-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-29
      相关资源
      最近更新 更多