Sliding windows and detecting objects of different sizes
10 questions on scanning a classifier across an image, the cost of doing so, sharing computation with convolutions, strides, scales and aspect ratios.
- 10 questions
- Stopwatch
- Instant feedback
Sample questions
Play now ↑Answers stay hidden. Start the quiz to play them.
Sample 1
A 20 by 20 window is slid over a 100 by 100 image in steps of 10 pixels, both horizontally and vertically. How many window positions are there?
- 100
- 64
- 81
How it works
- One question per screen. An answer is final once sent.
- You see right away whether you were right, with a short explanation.
- The stopwatch runs: on equal scores, the faster player ranks first.
- Only your best attempt counts, so replaying is never risky.
About this quiz
Suppose you have a good classifier that can look at a small, tightly cropped picture and tell you whether it shows a bicycle. How would you use it to find bicycles in a large street scene, where you do not know where they are or how big they will appear? The most direct answer is to slide a window over the whole image, cropping a patch at each position, asking the classifier about every patch, and noting where it answers yes. It works, and it is the ancestor of many detection methods. It is also, in its naive form, extremely wasteful. This quiz is about both facts.
You will see how such a detector is trained, from tight crops of the object and crops of plain background, and how it is applied. You will count window positions in a small example to see how fast the number grows, and meet the trade-off between a small stride, which locates objects precisely, and a large one, which saves work. You will see why the cost becomes prohibitive for deep networks and where the waste lies: neighbouring windows overlap, so nearly the same calculations are repeated again and again.
The cure is one of the nicest consequences of the convolutional structure. Because a convolutional layer is itself a sliding filter, the repeated work can be shared. And even the final fully connected layers can be re-read as convolutions, so that a network trained on small crops can be applied to a much larger image in one go, producing a whole grid of outputs, with only a small amount of extra computation for the new regions. The quiz also looks at how to deal with objects of different sizes and shapes, by rescaling copies of the image instead of building detectors for every window shape, and at a refinement that predicts small corrections to each box.
Some mistakes are common. People assume each window must be processed from scratch, that a finer stride is always better regardless of cost, and that several window shapes are needed for several aspect ratios. In fact, the shape problem can be turned into a problem of rescaling the picture. Even though the dedicated detection systems used today are more refined, the sliding window remains the cleanest way to understand what they have to do: look everywhere, at every scale, and do it cheaply. Many later ideas, from shared computation across positions to region proposals that skip empty areas, are answers to the limitations discussed here. Seeing the problem in its raw form makes those answers much easier to appreciate and to remember.
The quiz suits learners who know classification and bounding boxes, and practitioners curious about how early detectors worked. It needs only simple counting. There are 10 questions, each with an explanation, and it takes about four minutes.
Questions and answers
›How long does the quiz take?
About 3 to 4 minutes for 10 questions, at roughly 20 seconds each. An explanation follows each answer, including the counting for the example with window positions.
›Do I need to have studied detection before?
No, though it helps to know what a bounding box is. The quiz on bounding boxes and intersection-over-union covers that, and the questions here recall what is needed. Everything specific to sliding windows is explained as it comes up.
›What is a sliding window?
It is a method of finding objects using a classifier that works on small crops. You train the classifier on tight crops of the object and on crops of background, then scan a fixed-size window across the image, in horizontal and vertical steps, and give the contents of the window to the classifier at each position. A high probability marks a detection and the window gives its box.
›Why is the method costly?
There are very many window positions in an image, and the whole process may have to be repeated for several window sizes. Running a deep network with millions of parameters at each position is extremely expensive if done naively. Using larger steps saves work, but it makes the location of a detected object less precise.
›How do convolutions make it cheaper?
Windows that overlap would cause the same low-level calculations to be done several times. A convolutional layer already computes its filter responses at every position once, and neighbouring windows can share them. So processing a large image with the convolutional network gives the results for all window positions together, with little redundant work.
›How can a network trained on small crops process a bigger image?
By treating its fully connected layers as convolutional layers whose filters cover the whole of the small input. Enlarging the layers to match a bigger image then gives several output units that share the same weights, one for each window position. The first window's calculation is exactly what the original network would do, and the others need only a little extra.
›How are different object sizes and shapes handled?
Instead of using windows of many shapes, it is simpler and equivalent to keep one fixed window and make several copies of the image, each stretched or shrunk by a different horizontal and vertical factor. The window is scanned over each copy, and the scaling factors are used to convert a detected box back into the coordinates of the original image.
›How can the position of a box be refined?
By combining the sliding window with direct predictions of the box. The network gives continuous outputs that describe where the box lies relative to the window position, which fine-tunes the location. That avoids having to use a very fine stride, which would be costly, to obtain precise localisation.