InfogainLoss 层 [英] InfogainLoss layer

查看:14
本文介绍了InfogainLoss 层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望使用 InfogainLoss 在我的模型中.但是我很难正确定义它.

I wish to use a loss layer of type InfogainLoss in my model. But I am having difficulties defining it properly.

  1. 有没有关于INFOGAIN_LOSS层使用的教程/例子?

这一层的输入,类概率,应该是SOFTMAX层的输出,还是足以输入全连接层的顶部"?

Should the input to this layer, the class probabilities, be the output of a SOFTMAX layer, or is it enough to input the "top" of a fully connected layer?

INFOGAIN_LOSS 需要三个输入:类别概率、标签和矩阵 H.矩阵 H 可以作为层参数提供 infogain_loss_param { source: "fiename" }.
假设我有一个 python 脚本,它使用 dtype='f4 将 H 计算为 (L,L) 形状的 numpy.array'(其中 L 是我的模型中的标签数量).

INFOGAIN_LOSS requires three inputs: class probabilities, labels and the matrix H. The matrix H can be provided either as a layer parameters infogain_loss_param { source: "fiename" }.
Suppose I have a python script that computes H as a numpy.array of shape (L,L) with dtype='f4' (where L is the number of labels in my model).

  1. 如何将我的 numpy.array 转换为 binproto 文件,该文件可以作为 infogain_loss_param { source } 提供给模型?

  1. How can I convert my numpy.array into a binproto file that can be provided as a infogain_loss_param { source } to the model?

假设我希望将 H 作为第三个输入(底部)提供给损失层(而不是作为模型参数).我该怎么做?
我是否定义了一个顶部"是 H 的新数据层?如果是这样,该层的数据不会像训练数据递增一样在每次训练迭代中递增吗?如何定义多个不相关的输入数据"层,以及 caffe 如何知道从训练/测试数据"层批量读取,而从 H数据"层它知道整个训练过程只读取一次?

Suppose I want H to be provided as the third input (bottom) to the loss layer (rather than as a model parameter). How can I do this?
Do I define a new data layer which "top" is H? If so, wouldn't the data of this layer be incremented every training iteration like the training data is incremented? How can I define multiple unrelated input "data" layers, and how does caffe know to read from the training/testing "data" layer batch after batch, while from the H "data" layer it knows to read only once for all the training process?

推荐答案

1.有没有关于InfogainLoss层使用的教程/例子?:
一个很好的例子可以在这里找到:使用InfogainLoss来解决类不平衡问题.

1. Is there any tutorial/example on the usage of InfogainLoss layer?:
A nice example can be found here: using InfogainLoss to tackle class imbalance.

2.该层的输入,类概率,应该是 Softmax 层的输出吗?
从历史上看,根据 Yair 的回答,答案曾经是YES."InfogainLoss" 的旧实现需要是 "Softmax" 层或确保输入值在 [0..1] 范围内的任何其他层的输出.

2. Should the input to this layer, the class probabilities, be the output of a Softmax layer?
Historically, the answer used to be YES according to Yair's answer. The old implementation of "InfogainLoss" needed to be the output of "Softmax" layer or any other layer that makes sure the input values are in range [0..1].

OP 注意到在 "Softmax 之上使用 "InfogainLoss"" 层会导致数值不稳定.他的pull request,将这两层合二为一(很像SoftmaxWithLoss" 层),于 2017 年 4 月 14 日被接受并合并到官方 Caffe 存储库中.此处给出了这个组合层的数学计算.

The OP noticed that using "InfogainLoss" on top of "Softmax" layer can lead to numerical instability. His pull request, combining these two layers into a single one (much like "SoftmaxWithLoss" layer), was accepted and merged into the official Caffe repositories on 14/04/2017. The mathematics of this combined layer are given here.

升级后的层外观和感觉"与旧层完全一样,除了不再需要通过 Softmax" 层显式传递输入.

The upgraded layer "look and feel" is exactly like the old one, apart from the fact that one no longer needs to explicitly pass the input through a "Softmax" layer.

3.如何将 numpy.array 转换为 binproto 文件:

在蟒蛇中

H = np.eye( L, dtype = 'f4' ) 
import caffe
blob = caffe.io.array_to_blobproto( H.reshape( (1,1,L,L) ) )
with open( 'infogainH.binaryproto', 'wb' ) as f :
    f.write( blob.SerializeToString() )

现在您可以将 INFOGAIN_LOSS 层添加到模型原型中,H 作为参数:

Now you can add to the model prototext the INFOGAIN_LOSS layer with H as a parameter:

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

<小时>

4.如何加载 H 作为数据层的一部分


4. How to load H as part of a DATA layer

引用 Evan Shelhamer 的帖子:

目前无法让数据层以不同的速率加载输入.每次前向传递所有数据层都会前进.但是,恒定 H 输入可以通过制作一个只有 H 的输入 lmdb/leveldb/hdf5 文件来完成,因为数据层将循环并继续加载相同的 H.这显然会浪费磁盘 IO.

There's no way at present to make data layers load input at different rates. Every forward pass all data layers will advance. However, the constant H input could be done by making an input lmdb / leveldb / hdf5 file that is only H since the data layer will loop and keep loading the same H. This obviously wastes disk IO.

这篇关于InfogainLoss 层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆