Project 6 of 14, for Aaesha
Image Classifier
A convolutional network's forward pass by hand in NumPy, seeing the way the visual cortex starts to: edges on the Clocktower, pooling, and four trained filters that classify handwritten digits from thirty-six numbers each.
Sign up free to open itLog in
Act 7 needs a free account, so your work is saved as you go. Act 1 is open to everyone.
The brief
- AaeshaThe digit network reads a picture as sixty-four numbers in a row and has no idea which pixel's next to which.
- AaeshaEyes don't work like that, because cells in the visual cortex each watch one small patch and fire for an edge.
- NeilSo it's little grids slid across the picture, then. I trained four at home in PyTorch and copied out the numbers.
In seeing.py, by hand with NumPy, no SciPy or PyTorch. Neil's trained numbers are in filters.py.
convolve(image, kernel): slide the kernel over the picture. At each place it fits entirely, multiply it by the patch underneath and add the lot up. For an image of height H and width W and a kernel of height kh and width kw, the answer is (H - kh + 1, W - kw + 1).max_pool(feature, size=2): the biggest number in each size by size block. Rows and columns that don't make a whole block are dropped.conv_layer(image, kernels, biases): for each kernel, convolve, add that kernel's bias and apply relu. The maps come back stacked, shape (number of kernels, H', W').forward(image, params): the maps fromparams["kernels"]andparams["kernel_biases"], each pooled, flattened filter by filter into one row, thenrow @ params["W"] + params["b"]and softmax: ten chances.- Run as a program, it reads the 297 held-back digits from the Handwritten Digit Recogniser through Neil's filters.
A digit (8, 8) becomes maps (4, 6, 6), pooled to (4, 3, 3): 36 numbers, then 10 chances Read 289 of 297 digits it had never seen
What you learn
What's in it
- A window slid across a picture
- A window on the Clocktower
- A kernel that finds edges
- Edges
- Keeping the strongest
- The biggest in each block
- A network that sees
- How Paul would do it
- Fix Riya's version
- A network that sees
- Ship it