MLP and Image: The Relationship That Never Worked

Aditya Mohanty
2 min readJun 24, 2020
(Picture By Kelly Sikkema On Unsplash)

Introduction:

Multilayer perceptron or MLPs solved a major problem with single layer perceptron which was with respect to its inability to work with datasets that are not linearly separable. In case of multilayer perceptrons neurons are stacked on top of eachother . The following diagram shows the basic architecture of a multi-layer perceptron.

Pic Credit: Research Gate

As we can see the mlp architecture consists of an input layer, one or more hidden layer and an output layer.

Image Classification With MLP:

MLPs generally take 1-D vector as input. So before feeding our 2-D image to the model we have to flatten it out. For example if our image is having a dimension of 28*28 then the input layer would have 784 nodes. The following code snippet shows how to do it with keras

model = Sequential()model.add( Flatten(input_shape = (28,28))

Based on our requirement and the nature of the data we can experiment with the number of hidden layers. Also in the end we can add the number of classes that we wish to classify for our problem. The output layer will be a dense layer that will give a probability for each of the class. We can use the softmax activation function for the same.

Why MLPS Are Not The Best Choice:

One of the key aspect of any image is its spatial property. It tells a lot about the image, for example any pattern in a 2D image. Here in case of MLP in the initial stage we flattened the image into 1 dimension. This would lead to loss of information as we won’t be able to know if the pixels were connected to eachother or were in any grid. As an example mlp can’t actually detect square or circular shape because it could never know if the pixels were connected in such a shape as it was flattened out initially.

On the otherhand MLPs are basically dense layers. In case of a large image with good quality it can have millions of parameters in the initial layer only. This would make the training process hard as we would have to adjust all those weights in the later phase. As we add more number layers it might even become impossible to train a model with limited computational power.

This was a short overview about why MLPs are not the best choice for doing any task related to image.

--

--