# How to properly use Flatten layer?

Context

I'm trying to create net that will be able to recognize printed-like digits. Something like MNIST, but only for standard printing font.

Images are of the size 40x40 and I'd like to put them into feedforward net since ConvNet seems too powerful for this task.

Question

How should I use Flatten layer in this task?

Code

My current net:

X, test_X, y, test_y = train_test_split(X, y, test_size=0.25, random_state=42)

self.model = Sequential()
self.model.compile(loss="categorical_crossentropy",
optimizer="rmsprop",
metrics=['accuracy'])

self.history = self.model.fit(X, y, batch_size=256, epochs=20, validation_data=(test_X, test_y))
print(self.model.summary())


Example images

Current results

The Flatten layer is used for collapsing an ND tensor into a 1D tensor. In your case, the inputs appear to be $$28\times28$$ images, so Flatten will convert that into a tensor with shape $$1\times768$$. Note that no information is lost. Flatten layers are usually used where you have a convolutional layer with dimensions $$N\times M \times C$$ (where $$N$$,$$M$$ are the feature map sizes and $$C$$ is the number of channels) and want to fully connect with a Dense layer or another layer that only accepts 1D inputs. Flatten can also be used when the network is meant to output a feature vector from a final convolutional layer for image classification purposes using a different technique.