A layer that reshapes a given tensor. Parameters ---------- shape : tuple of int The output shape, see ``tf.reshape``. name : str A unique layer name. Examples -------- >>> x = tl.layers.Input([8, 4, 3], name='input') >>> y = tl.layers.Reshape(shape=
| 59 | |
| 60 | |
| 61 | class Reshape(Layer): |
| 62 | """A layer that reshapes a given tensor. |
| 63 | |
| 64 | Parameters |
| 65 | ---------- |
| 66 | shape : tuple of int |
| 67 | The output shape, see ``tf.reshape``. |
| 68 | name : str |
| 69 | A unique layer name. |
| 70 | |
| 71 | Examples |
| 72 | -------- |
| 73 | >>> x = tl.layers.Input([8, 4, 3], name='input') |
| 74 | >>> y = tl.layers.Reshape(shape=[-1, 12], name='reshape')(x) |
| 75 | (8, 12) |
| 76 | |
| 77 | """ |
| 78 | |
| 79 | def __init__(self, shape, name=None): #'reshape'): |
| 80 | super(Reshape, self).__init__(name) |
| 81 | self.shape = shape |
| 82 | |
| 83 | logging.info("Reshape %s" % (self.name)) |
| 84 | |
| 85 | self.build() |
| 86 | self._built = True |
| 87 | |
| 88 | def __repr__(self): |
| 89 | s = '{classname}(' |
| 90 | s += 'shape={shape},' |
| 91 | s += 'name=\'{name}\'' |
| 92 | s += ')' |
| 93 | return s.format(classname=self.__class__.__name__, **self.__dict__) |
| 94 | |
| 95 | def build(self, inputs_shape=None): |
| 96 | pass |
| 97 | |
| 98 | # @tf.function |
| 99 | def forward(self, inputs): |
| 100 | outputs = tf.reshape(inputs, shape=self.shape, name=self.name) |
| 101 | return outputs |
| 102 | |
| 103 | |
| 104 | class Transpose(Layer): |
no outgoing calls
no test coverage detected
searching dependent graphs…