我正在尝试实现 Mitigating Unwanted Biases with Adversarial Learning 中的梯度投影技术
模型架构是
- 1)输入层
- 2) 密集定长层
- 3) 自定义渐变项目层
- 4a) 任务 1 层
- 4b) 任务 2 层(对抗性任务)
我想使用自定义层 (3) 操纵任务 1 和任务 2 的渐变。目前我计划在自定义层的调用中有这样的东西
@tf.RegisterGradient('blah')
def proj_gradients(op, grad):
return grad[0] - grad[1]
g = K.get_session().graph
with g.gradient_override_map({'Identity': 'blah'}):
y = tf.identity(X)
是否有更直观的 Keras 方法来执行此操作?
请您参考如下方法:
tf.custom_gradient是这里使用的最佳工具。它允许您在调用站点定义梯度函数,具有比覆盖图更好的界面,并且可以很好地与急切执行配合使用。
