Caffe 中的多类别分类
Multiple category classification in Caffe
我想我们也许能够编译一些执行多类别分类的方法的含咖啡因的描述。
多类别分类我的意思是:包含多个模型输出类别的表示的输入数据and/or可以简单地在多个模型输出类别下分类。
例如包含猫狗的图像将(理想情况下)为猫狗预测类别输出 ~1,为所有其他类别输出 ~0。
基于this paper, this stale and closed PR and this open PR,caffe似乎完全可以接受标签。这是正确的吗?
构建这样的网络是否需要使用多个神经元(内积 -> relu -> 内积)和 softmax 层,如 page 13 of this paper;还是 Caffe 的 ip 和 softmax 目前支持多个标签维度?
当我将标签传递给网络时,哪个示例可以说明正确的方法(如果不是两者)?:
例如Cat eating apple 注:Python语法,不过我用的是c++源码。
第 0 列 - Class 已输入;
第 1 列 - Class 不在输入
中
[[1,0], # Apple
[0,1], # Baseball
[1,0], # Cat
[0,1]] # Dog
或
第 0 列 - Class 在输入中
[[1], # Apple
[0], # Baseball
[1], # Cat
[0]] # Dog
如果有任何不清楚的地方请告诉我,我会生成我要问的问题的图片示例。
问得好。我相信这里没有单一的 "canonical" 答案,您可能会找到几种不同的方法来解决这个问题。我会尽力展示一种可能的方式。它与您提出的问题略有不同,因此我将重新陈述问题并提出解决方案。
问题:给定一张输入图像和一组C
classes,对每个[=59=表示 ] 是否在图像中描绘。
输入:在训练时间,输入是一对图像和一个C
-dim 二进制向量,表示每个C
的 class classes 是否存在于图像中。
输出: 给定一张图像,输出一个 C
-dim 二进制向量(与您问题中建议的第二种形式相同)。
让 caffe 完成这项工作: 为了完成这项工作,我们需要使用不同的损失修改网络的顶层。
但首先,让我们了解 caffe 的通常使用方式,然后再研究所需的更改。
现在的情况: 图像被送入网络,经过 conv/pooling/... 层,最后通过 "InnerProduct"
层 C
输出。这些 C
预测进入 "Softmax"
层,该层抑制除最主要 class 以外的所有预测。突出显示单个 class 后,"SoftmaxWithLoss"
层会检查突出显示的预测 class 是否与基本事实匹配 class.
你需要什么:现有方法的问题是 "Softmax"
层基本上选择单个 class。我建议您 将 替换为 "Sigmoid"
layer that maps each of the C
outputs into an indicator whether this specific class is present in the image. For training, you should use "SigmoidCrossEntropyLoss"
而不是 "SoftmaxWithloss"
层。
因为一张图片可以有多个标签。最直观的方式是把这个问题看成一个 C 独立的二元分类问题,其中 C 是不同的总数类。所以很容易理解什么是:
add a "Sigmoid" layer that maps each of the C outputs into an indicator whether this specific class is present in the image, and should use "SigmoidCrossEntropyLoss" instead of the "SoftmaxWithloss" layer.
The loss is the sum of these C SigmoidCrossEntropyLoss.
我想我们也许能够编译一些执行多类别分类的方法的含咖啡因的描述。
多类别分类我的意思是:包含多个模型输出类别的表示的输入数据and/or可以简单地在多个模型输出类别下分类。
例如包含猫狗的图像将(理想情况下)为猫狗预测类别输出 ~1,为所有其他类别输出 ~0。
基于this paper, this stale and closed PR and this open PR,caffe似乎完全可以接受标签。这是正确的吗?
构建这样的网络是否需要使用多个神经元(内积 -> relu -> 内积)和 softmax 层,如 page 13 of this paper;还是 Caffe 的 ip 和 softmax 目前支持多个标签维度?
当我将标签传递给网络时,哪个示例可以说明正确的方法(如果不是两者)?:
例如Cat eating apple 注:Python语法,不过我用的是c++源码。
第 0 列 - Class 已输入; 第 1 列 - Class 不在输入
中[[1,0], # Apple [0,1], # Baseball [1,0], # Cat [0,1]] # Dog
或
第 0 列 - Class 在输入中
[[1], # Apple [0], # Baseball [1], # Cat [0]] # Dog
如果有任何不清楚的地方请告诉我,我会生成我要问的问题的图片示例。
问得好。我相信这里没有单一的 "canonical" 答案,您可能会找到几种不同的方法来解决这个问题。我会尽力展示一种可能的方式。它与您提出的问题略有不同,因此我将重新陈述问题并提出解决方案。
问题:给定一张输入图像和一组C
classes,对每个[=59=表示 ] 是否在图像中描绘。
输入:在训练时间,输入是一对图像和一个C
-dim 二进制向量,表示每个C
的 class classes 是否存在于图像中。
输出: 给定一张图像,输出一个 C
-dim 二进制向量(与您问题中建议的第二种形式相同)。
让 caffe 完成这项工作: 为了完成这项工作,我们需要使用不同的损失修改网络的顶层。
但首先,让我们了解 caffe 的通常使用方式,然后再研究所需的更改。
现在的情况: 图像被送入网络,经过 conv/pooling/... 层,最后通过 "InnerProduct"
层 C
输出。这些 C
预测进入 "Softmax"
层,该层抑制除最主要 class 以外的所有预测。突出显示单个 class 后,"SoftmaxWithLoss"
层会检查突出显示的预测 class 是否与基本事实匹配 class.
你需要什么:现有方法的问题是 "Softmax"
层基本上选择单个 class。我建议您 将 替换为 "Sigmoid"
layer that maps each of the C
outputs into an indicator whether this specific class is present in the image. For training, you should use "SigmoidCrossEntropyLoss"
而不是 "SoftmaxWithloss"
层。
因为一张图片可以有多个标签。最直观的方式是把这个问题看成一个 C 独立的二元分类问题,其中 C 是不同的总数类。所以很容易理解什么是
add a "Sigmoid" layer that maps each of the C outputs into an indicator whether this specific class is present in the image, and should use "SigmoidCrossEntropyLoss" instead of the "SoftmaxWithloss" layer. The loss is the sum of these C SigmoidCrossEntropyLoss.