Search code examples
pythonkerasconv-neural-networksequential

Keras - Confusion about number of input layer nodes


So, when input_dim=3, it means that the input to a layer is three nodes right? But what about when input_shape attribute is used and there are more than one values? For example:

model = Sequential()
model.add(Conv2D(32, (3, 3), input_shape=(82, 82, 3)))

Here, the convolutional layer has 32 output nodes, but how many input nodes does it have?

model.summary() gives this:

Model: "sequential_1"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
conv2d_1 (Conv2D)            (None, 80, 80, 32)        896       
_________________________________________________________________
activation_1 (Activation)    (None, 80, 80, 32)        0         
_________________________________________________________________
max_pooling2d_1 (MaxPooling2 (None, 40, 40, 32)        0         
_________________________________________________________________
conv2d_2 (Conv2D)            (None, 38, 38, 32)        9248      
_________________________________________________________________
activation_2 (Activation)    (None, 38, 38, 32)        0         
_________________________________________________________________
max_pooling2d_2 (MaxPooling2 (None, 19, 19, 32)        0         
_________________________________________________________________
conv2d_3 (Conv2D)            (None, 17, 17, 64)        18496     
_________________________________________________________________
activation_3 (Activation)    (None, 17, 17, 64)        0         
_________________________________________________________________
max_pooling2d_3 (MaxPooling2 (None, 8, 8, 64)          0         
_________________________________________________________________
flatten_1 (Flatten)          (None, 4096)              0         
_________________________________________________________________
dense_1 (Dense)              (None, 64)                262208    
_________________________________________________________________
activation_4 (Activation)    (None, 64)                0         
_________________________________________________________________
dropout_1 (Dropout)          (None, 64)                0         
_________________________________________________________________
dense_2 (Dense)              (None, 1)                 65        
_________________________________________________________________
activation_5 (Activation)    (None, 1)                 0         
=================================================================
Total params: 290,913
Trainable params: 290,913
Non-trainable params: 0
_________________________________________________________________

Solution

  • Here Input_shape is used for images :

    Your example contain images shape 82x82x3 ==20172 which is equal to input node:

    ** How would you check this **

    print(model.summary())
    

    model.summary gives you complete detail of each layer