Keras - Reshape Layers


Advertisements

Reshape is used to change the shape of the input. For example, if reshape with argument (2,3) is applied to layer having input shape as (batch_size, 3, 2), then the output shape of the layer will be (batch_size, 2, 3)

Reshape has one argument as follows −

keras.layers.v(target_shape)

A simple example to use Reshape layers is as follows −

>>> from keras.models import Sequential 
>>> from keras.layers import Activation, Dense, Reshape 
>>> 
>>> 
>>> model = Sequential() 
>>> layer_1 = Dense(16, input_shape = (8,8)) 
>>> model.add(layer_1) 
>>> layer_2 = Reshape((16, 8)) 
>>> model.add(layer_2) 
>>> layer_2.input_shape (None, 8, 16) 
>>> layer_2.output_shape (None, 16, 8)
>>>

where, (16, 8) is set as target shape.

Advertisements