The :class:`Stack` class is a layer for stacking a list of rank-R tensors into one rank-(R+1) tensor, see `tf.stack() `__. Parameters ---------- axis : int New dimension along which to stack. name : str A uniq
| 14 | |
| 15 | |
| 16 | class Stack(Layer): |
| 17 | """ |
| 18 | The :class:`Stack` class is a layer for stacking a list of rank-R tensors into one rank-(R+1) tensor, see `tf.stack() <https://www.tensorflow.org/api_docs/python/tf/stack>`__. |
| 19 | |
| 20 | Parameters |
| 21 | ---------- |
| 22 | axis : int |
| 23 | New dimension along which to stack. |
| 24 | name : str |
| 25 | A unique layer name. |
| 26 | |
| 27 | Examples |
| 28 | --------- |
| 29 | >>> import tensorflow as tf |
| 30 | >>> import tensorlayer as tl |
| 31 | >>> ni = tl.layers.Input([None, 784], name='input') |
| 32 | >>> net1 = tl.layers.Dense(10, name='dense1')(ni) |
| 33 | >>> net2 = tl.layers.Dense(10, name='dense2')(ni) |
| 34 | >>> net3 = tl.layers.Dense(10, name='dense3')(ni) |
| 35 | >>> net = tl.layers.Stack(axis=1, name='stack')([net1, net2, net3]) |
| 36 | (?, 3, 10) |
| 37 | |
| 38 | """ |
| 39 | |
| 40 | def __init__( |
| 41 | self, |
| 42 | axis=1, |
| 43 | name=None, #'stack', |
| 44 | ): |
| 45 | super().__init__(name) |
| 46 | self.axis = axis |
| 47 | |
| 48 | self.build(None) |
| 49 | self._built = True |
| 50 | logging.info("Stack %s: axis: %d" % (self.name, self.axis)) |
| 51 | |
| 52 | def __repr__(self): |
| 53 | s = '{classname}(axis={axis}' |
| 54 | if self.name is not None: |
| 55 | s += ', name=\'{name}\'' |
| 56 | s += ')' |
| 57 | return s.format(classname=self.__class__.__name__, **self.__dict__) |
| 58 | |
| 59 | def build(self, inputs_shape): |
| 60 | pass |
| 61 | |
| 62 | def forward(self, inputs): |
| 63 | outputs = tf.stack(inputs, axis=self.axis, name=self.name) |
| 64 | return outputs |
| 65 | |
| 66 | |
| 67 | class UnStack(Layer): |
no outgoing calls
searching dependent graphs…