# Stride and Calculation of Output Size

November 24, 2020 2021-10-04 8:03## Stride and Calculation of Output Size

In the last lesson, we discussed shifting the convolution filter (kernel) by one pixel at a time, i.e., by a stride of 1. Well, it is not necessary to move a convolution filter across an image by just taking a stride of 1.

Stride is the number of pixels shifts over the input matrix. The stride () taken during a series of convolution operation can be changed according to the need of the problem. When = 1, it means that the filter will be shifted by a step of one column of pixel values to the right or one row of pixel values to the bottom. Similarly, when = 2, it means that the filter will be shifted by a step of two columns of pixel values to the right or two rows of pixel values to the bottom and so on.

However, if you think for a moment, why would anyone want to take a larger stride since the neural network will be ignoring pixel values during computation. There are multiple reasons but here are some major ones:

- Taking a larger stride allows a series of convolution operations to be computed faster for a large dimension image (say, 3000×3000 pixels).
- Lesser memory is needed to store the results of the convolution operation.
- The size of the output tensor can be reduced to make the input to the next layer of a Convolutional Neural Network smaller.
- Since overlapping pixel values are ignored when selecting new regions, overfitting can be avoided.

## Finding the size of an output tensor after a series of convolution operations

Generally, in a Convolutional Neural Network, the input image undergoes multiple convolution operations, where each convolution operation might change the size of the input image. In this section you will learn an easy way to find the size on an output tensor after a series of convolution operations.

If x is the size of the input image tensor, x is the size of the convolution filter and is the value of stride taken, then, the size of the resulting tensor, x (after a series of convolution operation) can be found out using the following formula:

and,

where, means that a floating-point result is rounded to its closest smallest integer value.

We’ve noticed that in the first lesson, we had started with an image tensor of size 4×4 and a stride of 1. However, after performing a series of convolutions, the output tensor got reduced to a size of 2×2. Let us see if the above formula can show similar results for a filter size of 3×3,

and,

Thus, the size of the output tensor is 2 x 2.

With this, you now know about the Convolution Operation in CNNs. In the next chapter, you will be introduced to another important operation in CNNs, the Pooling Operation.

*Are you interested in working with data? Get a free trial month of LinkedIn Learning and learn Data Science and Machine Learning courses using Python, R, and SQL from top instructors. *

** Enroll in any one of the courses from the following fields today on LinkedIn Learning and start your free month of learning:**

*Disclaimer: When you subscribe to LinkedIn Learning, we may earn a small commission as an affiliate. We love the platform so much so that we have been using it ourselves at The Click Reader. *