MCPcopy Create free account
hub / github.com/tensorpack/tensorpack / grad_fg

Function grad_fg

examples/DoReFa-Net/dorefa.py:49–59  ·  view source on GitHub ↗
(x)

Source from the content-addressed store, hash-verified

47 @tf.custom_gradient
48 def _identity(input):
49 def grad_fg(x):
50 rank = x.get_shape().ndims
51 assert rank is not None
52 maxx = tf.reduce_max(tf.abs(x), list(range(1, rank)), keep_dims=True)
53 x = x / maxx
54 n = float(2**bitG - 1)
55 x = x * 0.5 + 0.5 + tf.random_uniform(
56 tf.shape(x), minval=-0.5 / n, maxval=0.5 / n)
57 x = tf.clip_by_value(x, 0.0, 1.0)
58 x = quantize(x, bitG) - 0.5
59 return x * maxx * 2
60
61 return input, grad_fg
62

Callers

nothing calls this directly

Calls 2

quantizeFunction · 0.85
shapeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…