Reshape
類別tf_keras.layers.Reshape(target_shape, **kwargs)
將輸入重塑為給定形狀的層。
輸入形狀
任意形狀,但輸入形狀中的所有維度都必須是已知/固定的。當將此層用作模型中的第一層時,請使用關鍵字參數 input_shape
(整數元組,不包括樣本/批次大小軸)。
輸出形狀
(批次大小,) + 目標形狀
範例
>>> # as first layer in a Sequential model
>>> model = tf.keras.Sequential()
>>> model.add(tf.keras.layers.Reshape((3, 4), input_shape=(12,)))
>>> # model.output_shape == (None, 3, 4), `None` is the batch size.
>>> model.output_shape
(None, 3, 4)
>>> # as intermediate layer in a Sequential model
>>> model.add(tf.keras.layers.Reshape((6, 2)))
>>> model.output_shape
(None, 6, 2)
>>> # also supports shape inference using `-1` as dimension
>>> model.add(tf.keras.layers.Reshape((-1, 2, 2)))
>>> model.output_shape
(None, 3, 2, 2)