了解输入维度,SoftmaxWithLoss和Caffe中的标签

时间:2016-07-14 09:57:22

标签: c++ neural-network deep-learning caffe softmax

我正在尝试使用自己训练有素的网络和我自己的C ++数据。我使用ImageData层对“.jpg”数据进行了网络训练和测试,然后实现了基本的caffe示例“classification.cpp”,逐个通过内存传递图像。结果我需要知道2个类的概率:
1 - 对象,
2 - 环境。

我的常规用途输入图如下:

layer {
    name: "data"
    top:  "data"
    top:  "label"
    type: "Input"
    input_param { shape: { dim: 1 dim: 3 dim: 256 dim: 256 }}
}

输出图层:

layer {
    name: "fc6"
    top:  "fc6"
    type: "InnerProduct"
    bottom: "drop5"
    inner_product_param {
        num_output: 2
        weight_filler {
            type: "xavier"
            std: 0.1
        }
    }
}

layer {
    name: "prob"
    top:  "prob"
    type: "SoftmaxWithLoss"
    bottom: "fc6"
    bottom: "label"
}

layer {
    name: "accuracy"
    top:  "accuracy"
    type: "Accuracy"
    bottom: "fc6"
    bottom: "label"
    include {
        phase: TEST
    }
}

在测试阶段,网络已达到准确度= 0.93,但现在经常使用C ++我无法弄清楚一些基本概念并在解析模型时出错。

Check failure stack trace:
...
caffe::SoftmaxWithLossLayer<>::Reshape()
caffe::Net<>::Init()
caffe::Net<>::Net()
...
Check failed: outer_num_ * inner_num_ == bottom[1]->count() (1 vs. 196608) Number of labels must match number of predictions; e.g., if softmax axis == 1 and prediction shape is (N, C, H, W), label count (number of labels) must be N*H*W, with integer values in {0, 1, ..., C-1}.

好的,1x3x256x256 = 196608,但为什么我需要这个标签计数? 我有一个文件“labels.txt”,如示例“classification.cpp”:

environment
object

为什么标签!=类? 我应该怎么做SoftmaxWithLoss和输入维度?

1 个答案:

答案 0 :(得分:0)

您没有为标签定义shape,我假设您每张图片只有一个标签。因此

layer {
  name: "data"
  top:  "data"
  top:  "label"
  type: "Input"
  input_param { shape: { dim: 1 dim: 3 dim: 256 dim: 256 }
                shape: { dim: 1 dim: 1 }}  # one label per image
}
相关问题