Resources from the book

Grid / Stride Visualizer

Section 21.3 · Compare labeled objects with stride-32, stride-16, and stride-8 grids.

Section 21.3.1

Purpose

Visualize the relationship between labeled objects and the detection-layer grids you are considering for your configuration. This is the chapter’s second step in evaluating detection-layer requirements.

The utility is not required to calculate custom anchors. Reviewing stride alongside bounding-box sizes helps you consider both box size and spatial arrangement.

Section 21.3.2

Why It Exists

Overlaying stride-32, stride-16, and stride-8 grids makes it easier to judge how closely spaced object centers relate to grid cells. It provides a visual reference while you develop the ability to picture these grids mentally.

The book explains that with experience, the author no longer needs this utility to visualize the grids. For a newcomer, the overlays make that relationship tangible.

Section 21.3.3

Input

Use an exported YOLO / Darknet training dataset. Place the script in the project folder, alongside the clip folders. Each clip must have lowercase images and labels subfolders, with matching image and annotation filename stems.

Unlike the recursive box-size collector in 21.3, this script examines clip folders directly beneath the supplied project folder. Clip folders and image filenames are processed in sorted order.

class_id  center_x  center_y  width  height
0         0.50      0.50      0.25   0.20

Annotations use normalized coordinates. The program converts them to box corners using the resized image dimensions. It supports PNG, JPG, and JPEG images, skips unreadable images, and skips annotation lines that do not contain five values. Five-value lines must be numeric.

Review 21.1 · Data Structure & Python Setup →

Section 21.3.4

Output

Each image is resized to the requested network resolution and displayed with its labeled boxes in green and the selected stride grid overlaid. A few representative images are often enough to assess the arrangement.

HeadStrideGrid at 416 × 416Grid color
13213 × 13Red
21626 × 26Blue
3852 × 52Yellow

These head numbers belong to this utility. Other software may number or order detection heads differently.

Stride 32 · larger objects

Each nut’s bounding-box center falls in a different grid cell. This is a favorable spatial arrangement, provided the objects are also large and visually distinct enough for that detection scale.

Stride 32 · larger objects: green label boxes on the book’s three-nut example.
Example from section 21.3 of the book.

Stride 32 · smaller, closely spaced objects

With the same 13 × 13 grid, two small nut centers fall in the same cell and the third is nearby. This can make learning and detection more difficult at this stride, particularly when similar objects compete for the same anchors.

Stride 32 · smaller, closely spaced objects: green label boxes on the book’s three-nut example.
Example from section 21.3 of the book.

Stride 8 · the same small objects

The finer 52 × 52 grid places each nut center in a different cell. The book identifies stride 8 as the likely better choice for these small, closely spaced nuts.

Stride 8 · the same small objects: green label boxes on the book’s three-nut example.
Example from section 21.3 of the book.
The grid is a visual aid.

A favorable arrangement is not a guarantee of detection performance. Consider object size, spacing, visual detail, and your actual model’s behavior together.

The guide behind the codeFrom the page
to the plant floor.
Practical Guide to AI Computer Vision Integration in Industrial ManufacturingExplore the Book