MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / dice

Function dice

modelzoo/features/multihash_variable/dien/script/utils.py:12–35  ·  view source on GitHub ↗
(_x, axis=-1, epsilon=0.000000001, name='')

Source from the content-addressed store, hash-verified

10from tensorflow.keras import backend as K
11
12def dice(_x, axis=-1, epsilon=0.000000001, name=''):
13 with tf.variable_scope(name, reuse=tf.AUTO_REUSE):
14 alphas = tf.get_variable('alpha'+name, _x.get_shape()[-1],
15 initializer=tf.constant_initializer(0.0),
16 dtype=_x.dtype)
17 input_shape = list(_x.get_shape())
18
19 reduction_axes = list(range(len(input_shape)))
20 del reduction_axes[axis]
21 broadcast_shape = [1] * len(input_shape)
22 broadcast_shape[axis] = input_shape[axis]
23
24 # case: train mode (uses stats of the current batch)
25 mean = tf.reduce_mean(_x, axis=reduction_axes)
26 brodcast_mean = tf.reshape(mean, broadcast_shape)
27 std = tf.reduce_mean(tf.square(_x - brodcast_mean) + epsilon, axis=reduction_axes)
28 std = tf.sqrt(std)
29 brodcast_std = tf.reshape(std, broadcast_shape)
30 x_normed = (_x - brodcast_mean) / (brodcast_std + epsilon)
31 # x_normed = tf.layers.batch_normalization(_x, center=False, scale=False)
32 x_p = tf.sigmoid(x_normed)
33
34
35 return alphas * (1.0 - x_p) * _x + x_p * _x
36
37class QAAttGRUCell(RNNCell):
38 """Gated Recurrent Unit cell (cf. http://arxiv.org/abs/1406.1078).

Callers 3

build_fcn_netMethod · 0.70
build_fcn_net_bf16Method · 0.70
ComputeMethod · 0.50

Calls 7

variable_scopeMethod · 0.80
reduce_meanMethod · 0.80
reshapeMethod · 0.80
rangeFunction · 0.50
get_variableMethod · 0.45
get_shapeMethod · 0.45
squareMethod · 0.45

Tested by

no test coverage detected