gpt4 book ai didi

numpy - InfogainLoss 层

转载 作者:行者123 更新时间:2023-12-03 13:23:51 24 4
gpt4 key购买 nike

我希望使用 InfogainLoss 类型的损失层在我的模型中。但是我很难正确定义它。

  • 有没有关于 INFOGAIN_LOSS 用法的教程/示例?层?
  • 如果该层的输入,即类概率,是 SOFTMAX 的输出层,还是输入全连接层的“顶部”就足够了?
  • INFOGAIN_LOSS需要三个输入:类别概率、标签和矩阵 H .
    矩阵 H可以作为层参数提供 infogain_loss_param { source: "fiename" } .
    假设我有一个计算 H 的 python 脚本作为 numpy.array形状 (L,L)dtype='f4' (其中 L 是我模型中的标签数量)。
  • 如何转换我的 numpy.array变成 binproto可以作为 infogain_loss_param { source } 提供的文件模型?
  • 假设我想要 H作为损失层的第三个输入(底部)提供(而不是作为模型参数)。我怎样才能做到这一点?
    我是否定义了一个“顶部”为 H 的新数据层? ?如果是这样,这层的数据不是每次训练迭代都会增加,就像训练数据增加一样吗?
    我如何定义多个不相关的输入“数据”层,以及 caffe 如何知道从训练/测试“数据”层批量读取,而从 H它知道在所有训练过程中只读取一次的“数据”层吗?
  • 最佳答案

    1.有没有关于的使用教程/例子InfogainLoss 层?:
    可以找到一个很好的例子here : 使用 InfogainLoss 解决类(Class)不平衡问题。

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

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

    升级后的图层“观感”与旧图层一模一样,除了 不再需要通过 "Softmax" 显式传递输入。层。

    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作为参数:
    layer {
    bottom: "topOfPrevLayer"
    bottom: "label"
    top: "infoGainLoss"
    name: "infoGainLoss"
    type: "InfogainLoss"
    infogain_loss_param {
    source: "infogainH.binaryproto"
    }
    }

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

    报价 Evan Shelhamer's post :

    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.

    关于numpy - InfogainLoss 层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27632440/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com