Decode CNN Layer to understand previous layer structure

Gaurav Karki
3 min readJun 10, 2021

Decoding CNN layer is interesting concept and quite easy to understand.

Let’s try to understand it example of image. Let’s see what happens if our input data is a image which is 2-dimensional.

In a layer, each pixel (eg. in CNN layer 1)represent receptive field (eg. in Input layer ) from previous layer.

We are considering Stride (s) = 2 w.r.t row and column. Height and Width of receptive field is also same denoted by f = 3.

Now I want to check in CNN layer 1 that first pixel belongs to which receptive field in input layer. For that I’ll use formula mentioned below:

Range is from (i or j) * s to (i or j) * s + f -1.

First pixel in CNN layer 1 have i (row) = 0, j (column) = 0

i and j are position of pixel in CNN layer 1.

Using i to find range of rows and j to find range of columns.

Example 1

Let’s trace the pixel denoted by red block in CNN layer 1. Now we are finding range of rows and columns in input layer which belong to pixel in CNN layer 1 at position (0 , 0).

From position,

i = 0 and j = 0

By applying formula:

Range of rows starts from

i * s = 0 * 2 = 0

Range of rows ends at:

(i * s) + f — 1 = (0 * 2) + 3–1 = 2

So we get range of rows = (0 , 2)

With same calculation and considering j value in formula instead I we’ll get range of columns also and in case of this example it is same means range of columns will be (0 , 2).

Example 2

Now we’ll consider example of pixel denoted by blue block in CNN layer 1 and trace it in input layer.

Position of pixel in CNN layer 1 = ( 0 , 3 )

i = 0

J = 3

By applying formula:

Range of rows starts from

i * s = 0 * 2 = 0

Range of rows ends at:

(i * s) + f — 1 = (0 * 2) + 3–1 = 2

So we get range of rows = ( 0 , 2 )

Range of columns starts from

j * s = 3 * 2 = 6

Range of columns ends at:

(j * s) + f — 1 = (3 * 2) + 3–1 = 8

So we get range of columns = ( 6 , 8 )

I hope these examples helped you to understand the concept and I’ll request reader to verify it by decoding the pixel denoted by green color in CNN layer 1.

Happy Learning!!!

--

--