tf.keras.layers.Reshape
Stay organized with collections
Save and categorize content based on your preferences.
Reshapes an output to a certain shape.
Inherits From: Layer
tf.keras.layers.Reshape(
target_shape, **kwargs
)
Arguments |
target_shape
|
Target shape. Tuple of integers,
does not include the samples dimension (batch size).
|
Arbitrary, although all dimensions in the input shaped must be fixed.
Use the keyword argument input_shape
(tuple of integers, does not include the samples axis)
when using this layer as the first layer in a model.
Output shape:
(batch_size,) + target_shape
Example:
# as first layer in a Sequential model
model = Sequential()
model.add(Reshape((3, 4), input_shape=(12,)))
# now: model.output_shape == (None, 3, 4)
# note: `None` is the batch dimension
# as intermediate layer in a Sequential model
model.add(Reshape((6, 2)))
# now: model.output_shape == (None, 6, 2)
# also supports shape inference using `-1` as dimension
model.add(Reshape((-1, 2, 2)))
# now: model.output_shape == (None, None, 2, 2)
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-10-01 UTC.
[null,null,["Last updated 2020-10-01 UTC."],[],[],null,["# tf.keras.layers.Reshape\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------|\n| [TensorFlow 2 version](/api_docs/python/tf/keras/layers/Reshape) | [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/keras/layers/core.py#L376-L476) |\n\nReshapes an output to a certain shape.\n\nInherits From: [`Layer`](../../../tf/keras/layers/Layer)\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.keras.layers.Reshape`](/api_docs/python/tf/keras/layers/Reshape), \\`tf.compat.v2.keras.layers.Reshape\\`\n\n\u003cbr /\u003e\n\n tf.keras.layers.Reshape(\n target_shape, **kwargs\n )\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Arguments --------- ||\n|----------------|---------------------------------------------------------------------------------------|\n| `target_shape` | Target shape. Tuple of integers, does not include the samples dimension (batch size). |\n\n\u003cbr /\u003e\n\n#### Input shape:\n\nArbitrary, although all dimensions in the input shaped must be fixed.\nUse the keyword argument `input_shape`\n(tuple of integers, does not include the samples axis)\nwhen using this layer as the first layer in a model.\n\n#### Output shape:\n\n`(batch_size,) + target_shape`\n\n#### Example:\n\n # as first layer in a Sequential model\n model = Sequential()\n model.add(Reshape((3, 4), input_shape=(12,)))\n # now: model.output_shape == (None, 3, 4)\n # note: `None` is the batch dimension\n\n # as intermediate layer in a Sequential model\n model.add(Reshape((6, 2)))\n # now: model.output_shape == (None, 6, 2)\n\n # also supports shape inference using `-1` as dimension\n model.add(Reshape((-1, 2, 2)))\n # now: model.output_shape == (None, None, 2, 2)"]]