如何将图层约束为概率矩阵?

时间:2017-05-09 10:32:16

标签: tensorflow

我最近阅读了这篇paper来处理卷积神经网络中的噪声标签。

他们通过形成简单的概率转移矩阵对标签噪声进行建模 softmax输出后约束线性层。

因此,作为一个例子,我们可能有一个3乘3的概率转移矩阵(3个类):

Example probability transition matrix. The sum of each column has to be 1.

该矩阵Q基本上通过反向传播以与网络其余部分相同的方式进行训练。但它需要被约束为概率矩阵。引自论文:

  

在使用Q和模型进行渐变步骤之后   权重,我们将Q投射回概率矩阵的子空间,因为它代表条件概率。

现在我想知道在tensorflow中实现这样一个层的最佳方法是什么。 我有一些想法,但我不确定什么可行,或者是最好的程序。

1)在完成任何训练之前,对模型中的约束进行硬编码,例如:

    # ... build conv model without Q
    [...]
    # shape of y_conv (output CNN) assumed to be a [3,1] vector
    y_conv = tf.nn.softmax(y_conv, 0)
    # add linear layer representing Q, no bias
    W_Q = weight_variable([3, 3])
    # add constraint: columns are valid probability distribution
    W_Q = tf.nn.softmax(W_Q, 0)
    # output of model:
    Q_out = tf.matmul(W_Q, y_conv)
    # now compute loss, gradients and start training

2)计算并将渐变应用于整个模型(包括Q),然后应用约束

    train_op = ...
    constraint_op = tf.assign(W_Q, tf.nn.softmax(W_Q,0))
    sess = tf.session()
    # compute and apply gradients in form of a train_op
    sess.run(train_op)
    sess.run(constraint_op)

我认为第二种方法与纸质报价更相关,但我不确定扩展外部任务会使培训混淆。

或许我的想法是香蕉。我希望你能给我一些建议!

0 个答案:

没有答案