MCPcopy
hub / github.com/tensorlayer/TensorLayer / TernaryDense

Class TernaryDense

tensorlayer/layers/dense/ternary_dense.py:17–108  ·  view source on GitHub ↗

The :class:`TernaryDense` class is a ternary fully connected layer, which weights are either -1 or 1 or 0 while inference. Note that, the bias vector would not be tenaried. Parameters ---------- n_units : int The number of units of this layer. act : activation function

Source from the content-addressed store, hash-verified

15
16
17class TernaryDense(Layer):
18 """The :class:`TernaryDense` class is a ternary fully connected layer, which weights are either -1 or 1 or 0 while inference.
19
20 Note that, the bias vector would not be tenaried.
21
22 Parameters
23 ----------
24 n_units : int
25 The number of units of this layer.
26 act : activation function
27 The activation function of this layer, usually set to ``tf.act.sign`` or apply :class:`SignLayer` after :class:`BatchNormLayer`.
28 use_gemm : boolean
29 If True, use gemm instead of ``tf.matmul`` for inference. (TODO).
30 W_init : initializer
31 The initializer for the weight matrix.
32 b_init : initializer or None
33 The initializer for the bias vector. If None, skip biases.
34 in_channels: int
35 The number of channels of the previous layer.
36 If None, it will be automatically detected when the layer is forwarded for the first time.
37 name : None or str
38 A unique layer name.
39
40 """
41
42 def __init__(
43 self,
44 n_units=100,
45 act=None,
46 use_gemm=False,
47 W_init=tl.initializers.truncated_normal(stddev=0.05),
48 b_init=tl.initializers.constant(value=0.0),
49 in_channels=None,
50 name=None, #'ternary_dense',
51 ):
52 super().__init__(name, act=act)
53 self.n_units = n_units
54 self.use_gemm = use_gemm
55 self.W_init = W_init
56 self.b_init = b_init
57 self.in_channels = in_channels
58
59 if self.in_channels is not None:
60 self.build((None, self.in_channels))
61 self._built = True
62
63 logging.info(
64 "TernaryDense %s: %d %s" %
65 (self.name, n_units, self.act.__name__ if self.act is not None else 'No Activation')
66 )
67
68 def __repr__(self):
69 actstr = self.act.__name__ if self.act is not None else 'No Activation'
70 s = ('{classname}(n_units={n_units}, ' + actstr)
71 if self.in_channels is not None:
72 s += ', in_channels=\'{in_channels}\''
73 if self.name is not None:
74 s += ', name=\'{name}\''

Callers 4

modelFunction · 0.90
modelFunction · 0.90
setUpClassMethod · 0.85
test_exceptionMethod · 0.85

Calls

no outgoing calls

Tested by 2

setUpClassMethod · 0.68
test_exceptionMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…