Layer 4 takes less time to compute than layer 1? Anyone got an explaination?

Hello,

I am new to machine learning and was running some diagnostics.

When I do a model.predict:

myModel = Model(inputs = self.model_ori.input, outputs= self.model_ori.layers[1].output)
starttime = time.time()
myModelResult = myModel.predict(img)
endtime = time.time()

OR

myModel = Model(inputs = self.model_ori.input, outputs= self.model_ori.layers[4].output)
starttime = time.time()
myModelResult = myModel.predict(img)
endtime = time.time()

How is it that the 4th layer takes less time to predict than the first layer?

Layer Number Layer Name Size (Kilobytes) Time to Process (Seconds)
1 conv2d (Conv2D) 977 0.0484
2 batch_normalization (BatchNormalization) 1230 0.0665
3 leaky_re_lu (LeakyReLU) 1020 0.0547
4 max_pooling2d (MaxPooling2D) 300 0.0353

Can someone explain this behaviour to me? I want to learn more about how these things work.

Hi @Lolcocks

Yes, MaxPooling2D layer takes lesser time compare to other layers because the way of computation done using this layer. MaxPooling simply selects the maximum value out of the each kernel whereas Convolution involves multiplications and additions at each location in the output.

Please refer to these APIs Conv2D, BatchNormalization, LeakyReLU and MaxPooling2D computations methodology for more details. Thank you.