def _lower_bound(inputs, bound, name=None):
"""Same as tf.maximum, but with helpful gradient for inputs < bound.
The gradient is overwritten so that it is passed through if the input is not
hitting the bound. If it is, only gradients that push `inputs` higher than
the bound are passed through. No gradients are passed through to the bound.
Args:
inputs: input tensor
bound: lower bound for the input tensor
name: name for this op
Returns:
tf.maximum(inputs, bound)
"""
with tf.name_scope(name, 'GDNLowerBoundTefla', [inputs, bound]) as scope:
inputs = tf.convert_to_tensor(inputs, name='inputs')
bound = tf.convert_to_tensor(bound, name='bound')
with tf.get_default_graph().gradient_override_map(
{'Maximum': 'GDNLowerBoundTefla'}):
return tf.maximum(inputs, bound, name=scope)
评论列表
文章目录