2

我正在尝试将我自己训练有素的网络与我自己的 C++ 数据一起使用。我在带有图层的“.jpg”数据上训练和测试了网络ImageData,然后实现了基本的 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
    }
}

在测试阶段,网络已经达到了accuracy=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 和输入维度?

4

1 回答 1

0

您没有定义shapefor 标签,我假设每个图像只有一个标签。因此

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
}
于 2016-07-14T10:09:10.160 回答