Neural Network Layers Explained for Beginners

How to know the number of layers and neurons in a Neural Network.

Anar Abiyev
2 min readDec 23, 2023

In a Neural Network, there are three types of layers:

  • Input
  • Hidden
  • Output

I will explain what they are and how many neurons each should have.

Input Layer

The input layer of your neural network depends on the dataset you are going to use for the task. For example, if the dataset consists of 28x28 pixel images, then your input layer needs to have 784 (28x28) neurons. Each pixel value will correspond to a neuron in the input layer.

For the input layer, you need to analyze the dataset and see how many neurons you need to feed that data into the model.

Hidden Layer

The number of hidden layers in neural networks is some kind of hyperparameter.

There is no rule like you need two hidden layers for this or three hidden layers for that.

It is determined by trial and error method.

But,

Some guidelines will help you to find the answer more efficiently.

  • Start with simple architecture and increase complexity gradually.
  • If the dataset is more complex, more hidden layers will help.
  • Consider domain knowledge, if there is a solution to a similar problem, refer to that architecture.

Output Layer

The output layer of neural networks depends on the task. If it is a regression problem one neuron is enough. On the other hand, the number of neurons is determined by the number of classes in the classification problem.

For example, when you predict which digit the picture is, then 10 neurons output layer will be used, one neuron for the probability of each digit.

--

--

Anar Abiyev

Writing about Data Science / Deep Learning and Self Improvement