def _binary_round(x):
"""
Rounds a tensor whose values are in [0,1] to a tensor with values in {0, 1},
using the straight through estimator for the gradient.
Based on http://r2rt.com/binary-stochastic-neurons-in-tensorflow.html
:param x: input tensor
:return: y=round(x) with gradients defined by the identity mapping (y=x)
"""
g = tf.get_default_graph()
with ops.name_scope("BinaryRound") as name:
with g.gradient_override_map({"Round": "Identity"}):
return tf.round(x, name=name)
skip_rnn_cells.py 文件源码
python
阅读 34
收藏 0
点赞 0
评论 0
评论列表
文章目录