【问题标题】:InfogainLoss layer blobs failureInfogainLoss 层 blob 失败
【发布时间】:2016-07-07 00:24:00
【问题描述】:

我正在尝试建立 caffe 的 infogain loss 层来工作。我已经看过帖子,解决方案,但对我来说它仍然不起作用

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

我想试试 infogain loss layer,因为我觉得我有类不平衡的问题。我的大部分图片都包含太多背景。

在我的最后一个卷积层 (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"
    }
 }

我的信息增益矩阵是由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) 

【问题讨论】:

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


    【解决方案1】:

    出了什么问题?

    您的错误来自"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,即“升级”信息增益损失层。此升级版本支持“沿轴损失”,就像您追求的那样。此外,它使“Softmax”层冗余,因为它在内部计算概率(参见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
        }
      }
      

    【讨论】:

    • 我还有一个错误。我编辑了我的问题。我在没有 infogain 层的情况下进行了尝试,只是使用了 Softmax 层,而 caffe 正在给我写出标签和概率。后者始终为 0.33333,因此它不会学到任何东西。至于标签我几乎没有 1,只有 0 和 2 这些是我图像上的背景,所以这就是为什么我认为这可能是一个类不平衡问题
    • @experimenter 1. 您现在从 infogain 层得到的错误是由于您定义的是每像素损失,而不是每图像损失。 SoftmaxWithLoss 支持这一点,但 infogain 不支持。 2. 似乎您遇到了类不平衡问题,您可能需要调整 infogain 层以处理每像素损失
    • 非常感谢。我可以试试这个修改版吗?我想我还需要将代码从 github 粘贴到我的 infogain_loss_layer.cpp 和 hpp 中。并使用此修改版本的文件重新编译 caffe。我需要更改 caffe 文件中的其他任何内容还是只需要修改这两个文件?
    • 你可以 clone from the PR: git clone https://github.com/shaibagon/caffe.git -b upgrade_infogain 应该可以解决问题。您可能想考虑“挑选”这个提交到您自己的存储库......我强烈建议您使用 git 工具进行此更改,而不是自己破解并复制文件。如果您不破坏 git 流程,跟踪更改并不断更新代码会更容易。
    猜你喜欢
    • 2015-02-22
    • 2017-12-17
    • 2016-11-18
    • 2017-01-05
    • 2018-06-12
    • 1970-01-01
    • 2015-07-31
    • 2011-04-14
    • 2014-08-07
    相关资源
    最近更新 更多