Caffe 输出层数精度 [英] Caffe output layer number accuracy

查看:33
本文介绍了Caffe 输出层数精度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我修改了 Caffe MNIST 示例 以对 3 类图片.我注意到的一件事是,如果我将输出层的数量指定为 3,那么我的测试准确度会急剧下降——下降到 40% 的低范围.但是,如果我 +1 并且有 4 个输出层,则结果在 95% 范围内.
我在我的数据集中添加了一个额外的图像类(所以 4 个类)并注意到同样的事情 - 如果输出层的数量与类的数量相同,那么结果是可怕的,如果它是相同的 +1,然后效果很好.

I've modified the Caffe MNIST example to classify 3 classes of image. One thing I noticed was that if I specify the number of output layers as 3, then my test accuracy drops horribly - down to the low 40% range. However, if I +1 and have 4 output layers, the result is in the 95% range.
I added an extra class of images to my dataset (so 4 classes) and noticed the same thing - if the number of output layers were the same as the number of classes, then the result was horrible, if it was the same +1, then it worked really well.

  inner_product_param {
    num_output: 3
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"

有谁知道这是为什么?我注意到,当我使用模型时,我使用 C++ 示例代码 在我的测试集中的图像上,它会抱怨我已经告诉它存在 4 个类,而我在我的标签文件中只提供了 3 个类的标签.如果我发明了一个标签并将其添加到文件中,我可以让程序运行,但是无论我给它什么图像,它都只会以 1.0 的概率返回一个类.

Does anyone know why this is? I've noticed that when I use the model I train with the C++ example code on an image from my test set then it will complain that I've told it that there are 4 classes present and I've only supplied labels for 3 in my labels file. If I invent a label and add it to the file, I can get the program to run, but then it just returns one of the classes with a probability of 1.0 no matter what image I give it.

推荐答案

需要注意的是,在微调和/或更改标签数量时,输入标签必须始终从 0 开始,因为它们在计算损失时用作输出概率向量的索引.
因此,如果你有

It is important to notice that when fine-tuning and/or changing the number of labels the input labels must always start from 0, as they are used as indices into the output probability vector when computing the loss.
Thus, if you have

 inner_product_params {
   num_output: 3
 }

您必须只有训练标签 0,1 和 2.

You must have training labels 0,1 and 2 only.

如果您使用带有标签 1,2,3 的 num_output: 3 ,caffe 无法表示标签 3,实际上有一个与标签 0 对应的冗余线未被使用.
正如您所观察到的,当更改为 num_output: 4 时,caffe 再次能够表示标签 3 并且结果有所改善,但参数矩阵中仍有未使用的行.

If you use num_output: 3 with labels 1,2,3 caffe is unable to represent label 3 and in fact has a redundant line corresponding to label 0 that is left unused.
As you observed, when changing to num_output: 4 caffe is again able to represent label 3 and the results improved, but still you have an unused row in the parameters matrix.

这篇关于Caffe 输出层数精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆