首页 文章

在TensorFlow中实施对抗性训练

提问于
浏览
5

我想为我的神经网络实现以下成本函数:

这利用神经网络的对抗性输入来改善泛化[ref] .

具体来说,我遇到了

部分的问题 . 在我的TensorFlow图中,我将

定义为操作 . 如何使用

以外的参数提供

到目前为止,我发现这样做的唯一方法是定义一个并行网络

,它与我的原始网络共享权重并在其 feed_dict 参数中传递它

. 如果可能的话,我想避免重新定义我的整个网络 . 我怎样才能做到这一点?


我的TensorFlow模型写成:

x = tf.placeholder(tf.float32, [None, 32, 32]);
... # A simple neural network
y = tf.add(tf.matmul(h, W1), b1);
cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(y, t));

可能相关:

tf.stop_gradient(input,name = None)停止渐变计算 . ......更多的东西......对抗性训练,通过对抗性的示例生成过程不会发生反向训练 .

https://www.tensorflow.org/versions/r0.7/api_docs/python/train.html#stop_gradient

1 回答

  • 6

    您需要以支持调用的方式编写模型

    output = model.fprop(input_tensor)
    

    要么

    output = model.fprop(input_tensor, params)
    

    fprop方法两次构建相同的前向传播表达式,但每次调用时输入张量不同:

    raw_output = model.fprop(clean_examples)
    adv_examples = ...
    adv_output = model.fprop(adv_examples)
    

    如果你想将它应用于我们的一个开源模型并且它不支持接口来执行此操作,请在github上提出问题 .

相关问题