A Filter With No Window

Convolutional ArchitecturesMedium+20 XP+20

A Filter With No Window

A 1×11\times11×1 convolution looks like a mistake. Its window covers a single pixel, so it sees no neighbours at all and cannot possibly detect an edge, a corner, or anything else spatial.

What it does see is the full depth — every feature map at that one position. It reads a column of numbers straight down through the block and returns a single number, and it does that at every position independently. The grid comes out exactly the size it went in; only the depth changes.

That is the operation Inception puts in front of its expensive paths, and the one a bottleneck block uses to squeeze 256 maps down to 64 before doing the 3×33\times33×3 work.

Task: write one_by_one(block, filters, biases), returning the output block as plain nested lists, rounded to 4 decimal places.

  • block is a list of feature maps: block[c][i][j] is the value of channel c at row i, column j. Every map has the same height and width.
  • filters is a list of filters. Each filter is a list holding one weight per input channel — a 1×11\times11×1 filter spanning the full input depth.
  • biases holds one bias per filter.
  • Return one feature map per filter, each the same height and width as the input maps. No activation function is applied — here the layer's only job is to change the depth.

Count what this costs: one weight per input channel per filter, and not one of them spatial. A 5×55\times55×5 path on a 256-deep block is over 800,000 weights; hand it a block this operation has already squeezed and that figure collapses by an order of magnitude, which is the only reason an Inception block is affordable at all.

Examples

block = [[[1.0, 2.0], [3.0, 4.0]], [[0.0, -1.0], [2.0, 0.5]], [[5.0, 0.0], [-2.0, 1.0]]]
filters = [[1.0, 0.0, 0.0], [0.2, -0.5, 0.1]]
biases = [0.0, -1.0]
returns [[[1.0, 2.0], [3.0, 4.0]], [[-0.3, -0.1], [-1.6, -0.35]]]
block = [[[2.0, 0.0, -1.0]], [[1.0, 4.0, 0.5]]]
filters = [[1.0, 1.0], [0.5, -0.25], [0.0, 2.0]]
biases = [0.0, 1.0, -0.5]
returns [[[3.0, 4.0, -0.5]], [[1.75, 0.0, 0.375]], [[1.5, 7.5, 0.5]]]

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run