ContentsThe library

How a Filter Reads a Picture

One Filter Is Never Enough

Last timeEdges, and Skipping Positions

A filter reads the whole depth of its input and returns one number, so a layer with a hundred filters produces a hundred channels for the next layer to read.

The picture arrives with three numbers at every position, one for each colour. A

three by three filter that reads only one of them is reading a third of the

input, which is not what anybody wants. So a filter is not nine weights. It is

nine weights per input channel, stacked into a block three wide, three tall and

as deep as the input, and it reads the whole block at once.

FIG 1One output value, with channels
which filter, and therefore which output channel
which input channel, summed over all of them
the offsets within the window, as before
one bias per filter, added after the sum
Three nested sums rather than two. The one over input channels is the new part, and the crucial thing about it is that it is a sum: all the channels go in and one number comes out. The filter index o is outside everything, which is why each filter is an independent computation.

So one filter turns a stack of any depth into a single flat map. Depth is

consumed. If a layer is to hand the next layer something with depth of its own,

it must have several filters, and that is the whole of the arrangement: a layer

with a hundred and twenty eight filters produces a hundred and twenty eight

maps, stacked, and the next layer sees an input of depth a hundred and twenty

eight.

This makes the depth of every internal layer a free choice. The three at the

input is a fact about colour. Everything after it is a number somebody picked,

and picking it is one of the two or three decisions that actually determine

whether a design is affordable.

FIG 2The loops, with depth
python
for o in range(Cout):                     # one independent filter per output channel
    for r in range(Hout):
        for c in range(Wout):
            total = b[o]
            for i in range(Cin):          # the new loop: read every input channel
                for u in range(k):
                    for v in range(k):
                        total += w[o][i][u][v] * x[i][r + u][c + v]
            y[o][r][c] = total
Six nested loops, and the product of their lengths is the multiplication count of the layer. Reading it as a product is how the cost formula is derived: the three outer loops give the output volume, the three inner ones give the size of one filter.

What a layer costs

Multiply the loop lengths together and the arithmetic falls out. The output has

height times width times the number of filters positions, and each one is a dot

product over the window area times the input depth.

The lesson stops here

3 more paragraphs to go

You have read the opening. The rest of the argument, the problems that check whether it landed, and the lines worth keeping at the end all come with a plan.

The first lesson of every course in the library reads the whole way through, free, so you can see exactly what the rest of them are.

See the planThe contents

This is the reading half

Starting the course gives you your own copy of it. Every idea on every page has problems standing under it, marked with a reason rather than a tick, and any sentence you do not believe can be opened and argued with. None of that can happen on a page nobody owns.

The contents

The rest of this course

  1. 01The Same Few Numbers, Everywhere
  2. 02The Constraint That Pays for Itselfopening only
  3. 03Where the Window Fits, and How Often It Stopsopening only
  4. 04One Filter Is Never Enoughyou are here
  5. 05The Slow Widening of the Viewopening only
  6. 06Throwing Away Where, to Keep Whatopening only
  7. 07Two Discounts, Each With a Conditionopening only
  8. 08It Was a Matrix Multiply All Alongopening only

Read alongside