What is Padding in Convolutional Neural Network’s(CNN’s) padding

(Multi-Class image classification step by step guide part 4)

Ayeshmantha Perera
Sep 2, 2018 · 2 min read

So what is padding and why padding holds a main role in building the convolution neural net.

So when it come to convolving as we discussed on the previous posts the image will get shrinked and if we take a neural net with 100’s of layers on it.Oh god it will give us a small small image after filtered in the end.

Image for post
Image for post

And also if we just take a 3 by 3 filter on top of gray scale image and do the convolving what will happen.So I decided to put an image to make it easy for who ever reads this.

Image for post
Image for post

So if you take this gray scale image.The pixel in the corner will only get covers one time but if you take the middle pixel it will get covered more than once basically what does that means is we have more info on that middle pixel so these are the two main downsides

  1. Shrinking outputs
  2. Loosing information on corners of the image

To overcome this we can introduce Padding to an image.So what is padding

Image for post
Image for post

It’s an additional layer that we can add to the border of an image.For an example see the figure below there one more layer added to the 4*4 image and now it has converted in to 5*5 image

Image for post
Image for post

So now there is more frame that covers the edge pixels of an image cool.More info more accuracy that’s how neural net works so we have more info now we can get more accuracy doneeeeeee.But well apart from that now we are getting an end image that is larger than the original okays now still the shrinking will happen but we can get kind of a good image than going forward like before without the padding.Cool so that’s how padding works.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store