InfogainLoss层blob失败

时间:2016-03-20 14:33:41

标签: machine-learning computer-vision neural-network deep-learning caffe

我正在努力建立caffe的infogain损失层。我已经看过帖子,解决方案,但对我而言,它仍然无效

我的数据lmdb尺寸是Nx1xHxW(灰度图像),我的目标图像lmdb尺寸是Nx3xH / 8xW / 8(rgb图像)。我的最后一个卷积层的维度是1x3x20x80。 output_size是3,  所以我有3个类,因为我的标签号是目标lmdb图像数据集中的(0,1,2)。

我想试试infogain损失层,因为我觉得我有类不平衡问题。我的大多数图像都包含太多背景。

在我的最后一个卷积层(conv3)之后,我有这些:

 layer {
    name: "loss"
    type: "SoftmaxWithLoss"
    bottom: "conv3"
    top: "loss"
 } 


 layer {
    bottom: "loss"
    bottom: "label"
    top: "infoGainLoss"
    name: "infoGainLoss"
    type: "InfogainLoss"
    infogain_loss_param {
      source: "infogainH.binaryproto"
    }
 }

我的infogain矩阵由InfogainLoss layer帖子生成(如Shai建议的那样)所以我的H矩阵是1x1x3x3维度(一个单位矩阵)。所以我的L是3,因为我有3个班级。 当我运行prototxt文件时一切都很好(尺寸没问题),但在我的最后一个卷积层(conv3层)后,我收到以下错误:

 I0320 14:42:16.722874  5591 net.cpp:157] Top shape: 1 3 20 80 (4800)
 I0320 14:42:16.722882  5591 net.cpp:165] Memory required for data:   2892800
 I0320 14:42:16.722892  5591 layer_factory.hpp:77] Creating layer loss
 I0320 14:42:16.722900  5591 net.cpp:106] Creating Layer loss
 I0320 14:42:16.722906  5591 net.cpp:454] loss <- conv3
 I0320 14:42:16.722913  5591 net.cpp:411] loss -> loss
 F0320 14:42:16.722928  5591 layer.hpp:374] Check failed: ExactNumBottomBlobs() == bottom.size() (2 vs. 1) SoftmaxWithLoss Layer takes 2 bottom blob(s) as input.

我仔细检查过,每个lmdb数据集文件名都已正确设置。我不知道会出现什么问题。有什么想法吗?

亲爱的@Shai

感谢您的回答。我提到了以下内容:

 layer {
    name: "prob"
    type: "Softmax"
    bottom: "conv3"
    top: "prob"
    softmax_param { axis: 1 }
 }

 layer {
    bottom: "prob"
    bottom: "label"
    top: "infoGainLoss"
    name: "infoGainLoss"
    type: "InfogainLoss"
    infogain_loss_param {
        source: "infogainH.binaryproto"
    }
 }

但我仍然有错误:

Top shape: 1 3 20 80 (4800)
I0320 16:30:25.110862  6689 net.cpp:165] Memory required for data: 2912000
I0320 16:30:25.110867  6689 layer_factory.hpp:77] Creating layer infoGainLoss
I0320 16:30:25.110877  6689 net.cpp:106] Creating Layer infoGainLoss
I0320 16:30:25.110884  6689 net.cpp:454] infoGainLoss <- prob
I0320 16:30:25.110889  6689 net.cpp:454] infoGainLoss <- label
I0320 16:30:25.110896  6689 net.cpp:411] infoGainLoss -> infoGainLoss
F0320 16:30:25.110965  6689 infogain_loss_layer.cpp:35] Check failed: bottom[1]->height() == 1 (20 vs. 1) 

1 个答案:

答案 0 :(得分:4)

出了什么问题?

您的错误来自"loss"图层,而不是"InfogainLoss"图层:您混淆了输出类概率的"Softmax"图层,而"SoftmaxWithLoss"图层输出(标量)损失值。

你应该怎么做?

  1. "loss"图层替换为"prob"图层"Softmax"图层:

    layer {
      name: "prob"
      type: "Softmax" # NOT SoftmaxWithLoss
      bottom: "conv3"
      top: "prob"
      softmax_param { axis: 1 } # compute prob along 2nd axis
    }
    
  2. 您需要计算第二维的损失,目前似乎"InfogainLoss"图层不支持此功能。您可能需要调整"InfogainLoss"图层以使"SoftmaxWithLoss"之类的功能允许沿任意轴计算损失。
    更新:我在BVLC/caffe上创建了一个pull request,即#34;升级&#34; infogain损失层。此升级版本支持&#34;沿轴损失&#34;就像你追求的那样。而且,它使&#34; Softmax&#34;层内部冗余,因为它在内部计算概率(见this thread) 升级后的层可以像这样使用:

    layer {
      bottom: "conv3" # prob is computed internally
      bottom: "label"
      top: "infoGainLoss"
      name: "infoGainLoss"
      type: "InfogainLoss"
      infogain_loss_param {
        source: "infogainH.binaryproto"
        axis: 1  # compute loss and probability along axis
      }
    }