问题描述
我希望在我的计算机中使用类型为 InfogainLoss
的损失层模型.但是我很难正确定义它.
I wish to use a loss layer of type InfogainLoss
in my model. But I am having difficulties defining it properly.
-
是否有关于
INFOGAIN_LOSS
层用法的教程/示例?
Is there any tutorial/example on the usage of
INFOGAIN_LOSS
layer?
该层的输入(类概率)应该是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脚本,将H
计算为形状为(L,L)
的numpy.array
和dtype='f4'
(其中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).
-
如何将我的
numpy.array
转换为可以作为模型的infogain_loss_param { source }
提供的binproto
文件?
How can I convert my
numpy.array
into abinproto
file that can be provided as ainfogain_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"
可能导致数值不稳定. 他的拉取请求,将这两层合并为一个层(类似于"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文件:
在python中
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
这篇关于InfogainLoss层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!