AI Fundamentals
Chapter 11 · How Machines See: Convolutional Networks

What a CNN sees

Point your camera at something. Chapter 11's 3×3 filters turn the video into feature maps, pooling shrinks them, and a real CNN shows what its early and deep layers see and names what you're holding. The step-by-step version is See a CNN work.

Your camera

On the video:

Chapter 11's vision tasks (§5.2): classification names the whole picture. MobileNet gives one label for everything it sees, so it can't draw a box.

Your video stays on this device. Nothing is uploaded, saved or recorded: the filters and the network run here in your browser. Your browser will ask for camera permission. You can say no and use a sample photo instead.

Or use a sample photo:
Filters: – fpsNetwork: –Backend: –Model: not loaded

C · A real CNN guesses §5.1

This is MobileNet, a CNN that Google trained on ImageNet (about 14 million photos; Chapter 11, §5.1). This version knows 1,000 everyday classes: mugs, bananas, laptops, backpacks, dog breeds and more, but not people. It's not the chapter's model. It's built the same way, with conv layers, then pooling, then a softmax over its classes.

A · Your filters, live §2

The video, in gray at 160 × 120, goes through four 3×3 filters, the same kind as in Chapter 11. Each one makes a feature map: bright where its pattern is. Move your hand: the vertical-edge map lights up along your fingers, wherever they are in the frame. That's weight sharing (§2.1): one filter, slid over the whole image.

Edit "My own" filter

Type any numbers. Choose "My own" in a slot above to see it live. Try a sharpen filter: 0 −1 0 / −1 5 −1 / 0 −1 0.

B · Pooling shrinks the map §3

2×2 max pooling keeps the biggest number in each 2×2 block. Each side halves, so you get 4× fewer numbers and no weights to learn. The edges you care about survive.

Feature map: 160 × 120 = 19,200
Pool once: 80 × 60 = 4,800
Twice: 40 × 30 = 1,200

D · Inside the CNN: simple patterns first, then complex §4

These are real feature maps from inside MobileNet, live. The early layer still looks like the picture: edges, colors, light and dark, like our filters in A. The deep layer is small and abstract: each map fires for a part it has learned, such as a handle, an eye or a wheel. The image gets smaller and deeper as it goes through the network.

Early layer

Deep layer

We show 8 of each layer's maps: the ones most active when you press this.

Try this

The same idea in Keras
import numpy as np
import tensorflow as tf
from tensorflow.keras.applications.mobilenet_v2 import MobileNetV2, preprocess_input, decode_predictions
from tensorflow.keras.preprocessing import image

# A CNN that Google already trained on ImageNet (1,000 classes): no training needed
model = MobileNetV2(weights='imagenet')
model.summary()   # Conv2D layers, then pooling, then Dense(1000, softmax)

img = image.load_img('mug.jpg', target_size=(224, 224))   # resize to the input size
x = image.img_to_array(img)          # (224, 224, 3), pixels 0-255
x = np.expand_dims(x, axis=0)        # (1, 224, 224, 3): a batch of one
x = preprocess_input(x)              # scale pixels to -1 ... 1

pred = model.predict(x)              # 1,000 probabilities
print(decode_predictions(pred, top=3)[0])   # e.g. [('n03063599', 'coffee_mug', 0.83), ...]

# Look inside: a model that outputs an early layer's feature maps
early = tf.keras.Model(model.input, model.get_layer('Conv1').output)
print(early.predict(x).shape)        # (1, 112, 112, 32): smaller image, more maps

This page runs MobileNet v1 (width 0.5) in TensorFlow.js, a smaller cousin of MobileNetV2, so it stays fast in a browser.

Credits. Sample photos (all CC0 / public domain, from Wikimedia Commons, cropped): coffee mug by Ryan Holloway; banana by Mike Dorner; cat by Adina Voicu; bicycle by Mojmír Churavý. Model: MobileNet v1 0.50 (Howard et al., 2017), TensorFlow.js weights hosted by Google (Apache 2.0). ImageNet class names from TensorFlow.js models (Apache 2.0). Detector: COCO-SSD (SSD with MobileNet v2 lite, trained on the COCO dataset's 80 object kinds; @tensorflow-models/coco-ssd 2.2.3, Apache 2.0).