Go to the profile of  Suraj Patidar
Suraj Patidar
Follow
I am machine learning and deep learning enthusiast.
2 min read

Things to Know In Keras

Things to Know In Keras

1) Units: The amount of neurons or cells the layer has inside it.

There are 3 input units, 4 units in first hidden layer , 4 in second hidden layer.

2) Shapes: Shapes are tuple representing how many elements an array or tensor has in each dimension.

For Ex: a shape (30,4,10)means an array or tensor with 3 dimensions containing 30 elements in the first dimension,4 in second dimension and 10 in third dimension in total there are 1200 elements(30*4*10).

3) Input shape: If you have 50 images of 30*30 pixels in 3 channels.Then, the input layer tesor must have these shape (input.shape=(30,30,3)), here Keras ignores the first dimension,which is batch size. Our model should be able to deal with any batch size, so we define only other dimensions.

If your model require the batch size then you may pass it with the help of batch_input_shape=(50,30,30,3).

Either way you choose, tensors in the model will have the batch dimensions.

So even if we used input_shape=(30,30,3), when Keras when sends you a message or when you print the model summary it will show you  (None,30,30,3).

The first dimension is the batch size, its 'None' because it can depending on how many examples you give for the training.

Relation between Shapes, Units & The Output Shape

The 'units'  of each layer will define the output shape ( the shape of the tensor that is produced by the layer and will be the input of the next layer)

Each type of layer work in a particular way.Dense layer have output shape based on 'units', convolutional layer has output shape based on 'filters'.But it is always based on some layer property.

In our case let's see what happen in case of Dense layer :-

A dense layer has output shape of ( batch_size,units) , so yes units the property of layer also defines the output shape.

Hidden layer 1 : 4 units ; output shape=(batch_size,4)                                                       Hidden layer 2 : 4 units ; output shape=(batch_size,4)                                                     Last layer : 1 unit, output shape=(batch_size,1)