【问题标题】:Understanding input dimentions, SoftmaxWithLoss and labels in Caffe了解 Caffe 中的输入维度、SoftmaxWithLoss 和标签
【发布时间】:2016-11-17 04:31:50
【问题描述】:

我正在尝试将我自己训练有素的网络与我自己的 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 和输入维度?

【问题讨论】:

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


    【解决方案1】:

    您没有为标签定义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
    }
    

    【讨论】:

    • 感谢您的回答,但如果我尝试使用您的层结构,我会得到:Error parsing text-format caffe.NetParameter: 51:21: Non-repeated field "input_param" is specified multiple times.
    • 谢谢,@Shai,它有效,看起来我开始解决以下不匹配问题)
    猜你喜欢
    • 2018-03-08
    • 1970-01-01
    • 1970-01-01
    • 2017-04-20
    • 2017-03-19
    • 2017-10-06
    • 2023-03-19
    • 2018-08-20
    • 2018-06-25
    相关资源
    最近更新 更多