在 TensorFlow 中实施对抗训练
Implementing Adversarial Training in TensorFlow
我想为我的神经网络实现以下成本函数:
&space;=&space;J(%5Ctheta,x,t)&space;+&space;J(%5Ctheta,x+%5Cepsilon&space;%5Cnabla&space;J(%5Ctheta,&space;x,&space;t)))
这利用神经网络的对抗性输入来提高泛化能力[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)
Stops gradient computation.
...lots more stuff...
- Adversarial training, where no backprop should happen through the adversarial example generation process.
https://www.tensorflow.org/versions/r0.7/api_docs/python/train.html#stop_gradient
您需要以支持像
这样的调用的方式编写您的模型
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 上提交问题。
我想为我的神经网络实现以下成本函数:
这利用神经网络的对抗性输入来提高泛化能力[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)
Stops gradient computation.
...lots more stuff...
- Adversarial training, where no backprop should happen through the adversarial example generation process.
https://www.tensorflow.org/versions/r0.7/api_docs/python/train.html#stop_gradient
您需要以支持像
这样的调用的方式编写您的模型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 上提交问题。