RECEPTIVE FIELD

Ch 1 ▸ Why not a dense layer? ▸ Module 1/4

  1. 1Images are numbers
  2. 2Dense layers
  3. 3Counting parameters
  4. 4Lost neighbors

Images are numbers.

A digital image is a grid of numbers. A pixel is one square of that grid, and it holds the brightness of the image at that spot. In this book 0 is black, 1 is white, and anything in between is a shade of gray. An image in which every pixel holds a single brightness is called a grayscale image. Color images store three numbers per pixel, and they wait until chapter 4, so every image before then is grayscale.

Pixels are named by their row and column, both counted from 0, starting at the top-left. So pixel (2, 5) is in the third row from the top and the sixth column from the left.

The duck in figure 1.1 is 16 pixels wide and 16 pixels tall, so it’s 256 numbers. Point at any pixel to read its value.

Flattening

The layers in this chapter don’t take a grid. They take a list. Flattening turns a grid into a list by laying its rows end to end: row 0 first, then row 1, then row 2, and so on. The 16×16 duck becomes a list of 256 numbers.

FIG 1.1 ▸ FLATTEN16×16 → 256 NUMBERS
0163248648096112128144160176192208224240THE STRIP · ROW 0, THEN ROW 1, THEN ROW 2, …↑←→↓PIXEL (ROW 4, COLUMN 11)POSITION IN THE STRIP4 × 16 + 11 = 75VALUE 0.00ITS NEIGHBORS IN THE STRIPABOVE 59 (−16)LEFT 74 (−1)RIGHT 76 (+1)BELOW 91 (+16)
Image
Size
Press Flatten to lay the rows end to end. Point at any pixel, in the grid or the strip, to see where it lands. Its left and right neighbors stay next to it, but the pixels above and below end up 16 places away.

Every pixel lands at a predictable position. Row 0 fills positions 0 to 15, row 1 fills 16 to 31, and in general a pixel at row rr and column cc of an image nn pixels wide lands at

position=r×n+c\text{position} = r \times n + c

Pixel (2, 5) of the duck lands at 2×16+5=372 \times 16 + 5 = 37.

What happens to neighbors

Point at a pixel in the middle of the duck. Its left and right neighbors land right next to it in the list, one position on either side. But the pixel above it lands 16 positions earlier, and the pixel below lands 16 positions later. Switch the image to 32×32, and those neighbors are 32 positions away.

Nothing is lost. If you know the width, you can cut the list back into rows and rebuild the image exactly. The list itself, though, has no record of which numbers were neighbors, and two pixels that touched in the image can end up far apart in it. The last module of this chapter is about what that costs.

Knowledge check ▸ 4 questions

Before you move on.

Answer every question correctly to unlock the next module. A wrong answer gets a hint, and you can try again as many times as you like.

  1. 1A 28×28 grayscale image is flattened. How many numbers are in the list?

  2. 2A 16×16 image is flattened. Counting from 0, at what position does the pixel at row 3, column 4 land?

  3. 3In a flattened 32×32 image, how many positions apart are a pixel and the pixel directly below it?

  4. 4What does flattening lose?

0 of 4 answered correctly.

🔒 Next module: Dense layers