What is the role of Flatten in Keras. I am executing the code below and it's a two layered network. The shape of it's 2-Dimensional data is (4,3) and the output is of 1-Dimensional data of shape (2,5):

model = Sequential()

model.add(Dense(16, input_shape=(4, 3)))

model.add(Activation('relu'))

model.add(Flatten())

model.add(Dense(4))

model.compile(loss='mean_squared_error', optimizer='SGD')

c = np.array([[[2, 3], [4, 5], [6, 7]]])

u = model.predict(c)

print u.shape

with flatten function it prints that u has shape(2,5) but when I remove it the shape of y changes to (2,4,5).

As I know, model.add(Dense(16, input_shape=(3, 2))) this function here is used to create a hidden fully-connected layer of 16 nodes. And every node is connected with every 4x3 input elements. Hence all the 16 nodes of first laser are flat. This means the output we should get from first layer should be (2,17) which is used by second layer as input and it gives data of shape (2,5) as output.

So here my question is why am I further flatting it, when the first layer's output is already flat?