Skip to content

Computer Vision Basics

Glossary

110 terms from Computer Vision Basics, in plain words, each with the chapter that teaches it.

A

accuracy
The share of photos the model labels correctly. It can mislead when one class is rare, because always answering "not damaged" scores 88% here.
activations
The numbers a layer outputs for one input photo. Grad-CAM keeps a late layer's activations and weights them by their gradients.
AdamW
An optimizer that updates a neural network's weights during training, using adaptive step sizes and weight decay. You give it the parameters to train and a learning rate, such as `lr=3e-3`.
alpha channel
An extra channel that stores transparency. An RGBA image has four channels, so you convert it with `img.convert("RGB")` before giving it to a model that expects three.
antialias
An option on `Resize` that smooths the image while shrinking it, so the small version doesn't look jagged. It is on by default, and writing `antialias=True` makes the intent explicit.
aspect ratio
An image's width divided by its height. Resizing to a different ratio squashes the photo, so cropping to the target ratio (such as a square) first avoids distortion.
augmentation
Random changes to training photos, such as crops, flips and color shifts, that keep the label true. The network sees a slightly different version of each Kettle & Crane photo every epoch, so it can't simply memorize them.
average precision (AP)
A single number that summarizes precision across all possible thresholds. Guessing scores about the share of positive photos (0.12 for damage here) and a perfect model scores 1.

B

backbone
The layers of a network that turn a photo into feature maps, before the head. In TinyNet it is `features`, and in transfer learning it is the part you keep from the pretrained model.
batch
A group of examples processed together. Images in a batch must be the same size, and the batch axis N comes first: (N, C, H, W).
batch normalization
A layer that rescales each channel to mean 0 and standard deviation 1 across a batch, then applies a learned scale and shift, which makes training faster and steadier. It keeps running averages that it uses in `eval()` mode.
BCEWithLogitsLoss
The loss for a yes/no question. It takes one raw score (logit) per photo and float labels of 0 or 1, and its `pos_weight` option makes the rare class count more.
bounding box
The smallest upright rectangle around an object, stored as four numbers. torchvision's standard format is XYXY, and a set of boxes is an (N, 4) float tensor.
box formats (XYXY, XYWH, CXCYWH)
Three ways to write a box: XYXY is (x1, y1, x2, y2) for the top-left and bottom-right corners (torchvision's standard), XYWH is (x, y, width, height), and CXCYWH is the center plus width and height. Mixing them up draws boxes in the wrong place.
box helpers (box_convert, box_iou)
`torchvision.ops.box_convert` converts boxes between formats such as XYXY and XYWH. `box_iou` computes the IoU of every box in its first argument against every box in its second, one row per true box and one column per guess.
broadcasting
PyTorch's rule for combining tensors of different shapes by stretching size-1 axes. It lets a (3, 1, 1) tensor apply one mean or std per channel across a whole image.

C

CenterCrop
A transform that cuts a square out of the middle of an image. After `Resize(64)` it gives undistorted 64 × 64 squares, at the cost of losing the edges of wide photos.
channel
One layer of an image's numbers, such as all its red values. An RGB photo has three channels, and a convolution layer's output has one channel per filter.
channels-first shape (N, C, H, W)
The axis order PyTorch image layers expect: batch, channels, height, width. Pillow and NumPy images are (H, W, C), so `permute` reorders them and `unsqueeze(0)` adds the batch axis.
checkpoint
A saved file holding a trained model's weights. It can also store extras such as the class names, image size and normalization numbers, so whoever loads it can prepare photos exactly as in training.
class imbalance
A situation where one class has far fewer examples than another, such as 28 damaged photos among 240. Accuracy then misleads, because always answering "not damaged" scores 88%.
class index
The whole number a network uses for each class, such as bag = 0 and box = 1. `ImageFolder` assigns them alphabetically, so save the `classes` list with the model to turn answers back into words.
CNN (convolutional neural network)
A neural network built from convolution layers that slide small learned kernels over an image. TinyNet is a CNN made of four conv, BatchNorm, ReLU and pooling blocks.
COCO
A dataset of everyday photos labeled with boxes and masks for 80 kinds of object, including cup, bowl and handbag. torchvision's pretrained detectors were trained on it.
Colab
Google's browser-based notebook service, which runs Python code without any local setup. It offers a free GPU, which makes training faster.
ColorJitter
A random transform that changes brightness, contrast and similar properties by up to a given share on each call. It imitates dim kitchens and uneven lighting in customers' photos.
Compose
A transform that takes a list of transforms and runs them in order, so a whole preprocessing recipe becomes one callable object.
computer vision
Getting a computer to answer questions about images: what is in a photo, where it is, and which pixels belong to it.
confidence
The probability a model gives its predicted class. Priya can route photos above a confidence cut-off automatically and send the rest to a person.
confusion matrix
A table that counts every combination of true class (rows) and predicted class (columns). The diagonal holds the correct predictions, and the off-diagonal cells show which classes get mixed up.
convolution
An operation that slides a small grid of weights (the kernel) across an image, multiplying and summing at each position. It produces a feature map showing where a pattern such as an edge appears.
CrossEntropyLoss
The usual loss for picking one class out of several. It compares the logits with the class index, and its optional `weight` gives each class its own weight.
CVAT
Free tools for drawing bounding boxes on photos to create detection training data.

D

DataLoader
A PyTorch object that groups a dataset's examples into batches, optionally shuffled. Only the training loader shuffles, so validation and test results line up with file names.
Dataset
A PyTorch class with `__len__` and `__getitem__` that returns one example at a time. You write your own, like `DamageDataset`, when labels live in a file instead of folder names.
dynamic_shapes
An export option that lets chosen input axes, such as the batch size, vary instead of being fixed to the example input's size.

E

eval mode and train mode
Switches that change how some layers behave: in `train()` mode batch normalization uses each batch's statistics, while `eval()` mode uses its running averages. Use `eval()` for validation, testing and inference.
EXIF
Camera information stored inside a photo file, such as a note saying the image should be rotated. `Image.open` ignores it, so customer phone photos can show up sideways unless you call `ImageOps.exif_transpose`.
exporting
Saving a model's computation so it runs without your Python code, and even without PyTorch. ONNX and `torch.export` are two common routes.

F

F1
A single score that balances precision and recall, printed by `classification_report`.
false flag and miss
A false flag is an undamaged photo the model flags; a miss is a damaged photo it fails to flag. Giving each a cost (for example 1 minute versus 30) lets you choose a decision threshold that minimizes total cost.
Faster R-CNN
A pretrained object detector in torchvision. It takes a list of images and returns boxes, labels and scores. To train your own, you swap its box predictor head for one with your number of classes, counting "background" as a class.
feature extraction
Transfer learning where the backbone is frozen and only the new head trains. It is fast and suits very few photos or photos like the pretraining data.
feature map
One channel of a convolution layer's output, showing where a particular pattern was found in the image. For example, the vertical-edge kernel produces a map that lights up across the edge.
fine-tuning
Transfer learning where the whole network trains, often with a smaller learning rate for the backbone than for the new head. It suits a few hundred photos or more.
freezing
Setting `requires_grad = False` on weights so they don't change during training. Frozen BatchNorm layers must also be put back in `eval()` mode so their running averages stay fixed.

G

global average pooling
Averaging each feature map down to one number, whatever its size. It lets TinyNet accept different image sizes and feeds a fixed 128 numbers to the head.
Grad-CAM
A heat map showing where a late convolution layer found evidence for a class. It weights the layer's feature maps by their average gradients, keeps the positive part and resizes the result to the photo.
grayscale
An image with a single channel of brightness values per pixel (Pillow mode `"L"`), so its array has no channel axis.

H

head
The final layer or layers that turn the backbone's features into class scores. In TinyNet it is one `nn.Linear`, and in transfer learning you replace it with a new one for your own classes.
hook
A function that PyTorch calls at a certain moment, such as when a layer runs or when a gradient is computed. Grad-CAM uses hooks to capture a layer's activations and gradients without editing the model.

I

image classification
Picking one label for a whole photo from a fixed list, like deciding whether Priya's photo shows a bag, box, mug or notebook.
ImageFolder
A torchvision dataset that treats each subfolder name as a class label. It sorts classes alphabetically, so you should save `classes` with a trained model.
ImageNet
A dataset of over a million labeled photos in 1,000 categories, which most pretrained vision networks learned from. Its channel mean and std are the numbers you see in nearly every example.
inference
Using a trained model to make predictions. It needs `eval()` mode, no gradient tracking (`torch.inference_mode()`), the validation preprocessing and the training class order.
IoU (intersection over union)
The overlap area of two boxes or masks divided by the area they cover together, from 0 (no touch) to 1 (identical). A predicted box usually counts as correct when it has the right label and an IoU of at least 0.5.

K

kernel
The small grid of weights a convolution slides across an image. Training chooses its numbers, and early-layer kernels typically become edge and color detectors.

L

leakage
When near-duplicate photos, such as three shots of the same broken mug, land in both training and test sets, so the test score rewards memory. The fix is to split by source, such as ticket, customer or day.
logit
A model's raw output score before softmax or sigmoid turns it into a probability.

M

mask
A true/false tensor the size of the photo that marks which pixels belong to an object. Segmentation models predict masks, such as the pixels of spilled beans.
max pooling
A layer that keeps the largest value in each window. With a 2 × 2 window it halves the height and width and has no weights.
mean average precision (mAP)
The standard detection score: average precision averaged over classes and, in the COCO version, over IoU thresholds from 0.5 to 0.95.
multi-task model
One network with a shared backbone and a separate head for each question. Kettle & Crane's `TwoHeadNet` has one head for the product and one for damage, and trains both at once.

N

normalizing
Subtracting each channel's mean and dividing by its standard deviation, using numbers from the training photos (or the pretrained model's, usually ImageNet's). The same normalization must be used in training, testing and real use.

O

object detection
Finding objects in a photo as boxes, each with a label and a score. It answers "what objects are where", such as two mugs and a bag in one ticket photo.
OneCycleLR
A learning-rate schedule that warms the rate up and then lowers it smoothly. `kc.fit` steps it after every batch, and `max_lr` takes one peak rate per parameter group.
ONNX (Open Neural Network Exchange)
An open, widely supported file format for exported models. An ONNX file can run without your Python model code or PyTorch.
ONNX Runtime
Microsoft's free inference engine for running ONNX model files, usable from Python, C#, Java, JavaScript and on phones. It can run a model faster per photo than PyTorch; in one test it was about three times faster.

P

padding
Extra zero pixels added around an image's border before a convolution. `padding=1` keeps the size unchanged with 3 × 3 kernels.
parameter group
A set of parameters given to the optimizer with its own learning rate. Gentle fine-tuning uses two groups: a slower backbone and a faster head.
permute
Tensor shape operations. `permute` reorders axes, as in turning (H, W, C) into (C, H, W). `unsqueeze(0)` adds a batch axis, and `squeeze(1)` removes an axis of size 1.
Pillow
Python's standard library for opening, cropping, resizing and saving images, imported as `PIL`.
pixel
One square of an image's grid, holding a color stored as three numbers (red, green and blue) from 0 to 255.
pos_weight
An option of `BCEWithLogitsLoss` that multiplies the loss on positive (rare) examples. Setting it to undamaged ÷ damaged photos, about 7.6 on the original 240 photos, makes the damaged photos count as much in total as the rest.
precision
Of the photos the model flagged as a class, the share that really belong to it. Low precision for damage means false flags that waste Alex's time.
pretrained
A network already trained on a large dataset such as ImageNet and ready to adapt to your own photos.

R

RandomErasing
One of several image augmentations: `RandomErasing` blanks a random rectangle, `RandomRotation` turns the photo, `RandomPerspective` skews it, `GaussianBlur` blurs it, and `TrivialAugmentWide` applies one random change of random strength. Some, like erasing, can hide the evidence for a label such as damage, so they may not keep the label true.
RandomHorizontalFlip
A random transform that mirrors the photo half the time. A flipped mug is still a mug, though text you need to read shouldn't be flipped.
RandomResizedCrop
A random transform that cuts a rectangle covering a chosen share (`scale`) of the photo and resizes it. Its default scale (0.08 to 1.0) is aggressive and can crop away the product or the damage.
recall
Of the photos that really belong to a class, the share the model found. Low recall for damage means missed packing problems.
receptive field
The patch of the input photo that one output position depends on. It grows with each layer, and after TinyNet's four blocks it covers 46 × 46 pixels of a 64 × 64 photo.
ReLU
An activation function that keeps positive values and turns negatives into 0. Each TinyNet block applies it after batch normalization, and Grad-CAM uses it to keep only positive evidence.
Resize
A transform that changes image size. `Resize(64)` scales the shorter side to 64 and keeps the aspect ratio, while `Resize((64, 64))` forces the exact size and squashes the photo.
ResNet-18
A classic 18-layer CNN with 11.7 million weights, available in torchvision with ImageNet-pretrained weights. Its ImageNet head is called `fc`.
RGB
An image with red, green and blue channels, each pixel storing how much of each color to mix, from 0 to 255.

S

saliency map
A map of how much each pixel change would alter a class score, computed as the gradient of the score with respect to the input pixels. It is quick but noisy, showing sensitivity rather than evidence.
scikit-learn
A Python machine-learning library that supplies evaluation metrics such as `confusion_matrix`, `classification_report` and `average_precision_score`. It is often used alongside scikit-image, a separate library for image processing that also provides sample photos such as the coffee cup.
segmentation
Labeling every pixel of a photo, producing a mask. It answers "which pixels belong to what".
semantic and instance segmentation
Two kinds of segmentation. Semantic segmentation gives each pixel a class, and instance segmentation also separates individual objects of one class, such as "mug 1" and "mug 2".
Shapes-10
A stand-in pretraining dataset of 6,000 photos of ten simple shapes on tabletops. It is used to pretrain a small network (`TinyNet`) in minutes so it can serve as a reusable backbone for transfer learning.
shortcut
A spurious clue, such as the background or table, that a model uses instead of the object itself. Grad-CAM maps that sit off the object are a warning sign, and the fix is in the data.
sigmoid
A function that turns one logit into a probability between 0 and 1. It is used for the yes/no damage output.
SmoothGrad
A way to make saliency maps less noisy by averaging them over several copies of the photo with a little random noise added.
softmax
A function that turns a row of class logits into probabilities that add up to 1. The largest probability is the model's confidence.
state_dict
A model's weights stored as a dictionary. It holds only weights, so you must also save class names and preprocessing settings, and the saved shapes must match the model you load into.
stride
How many pixels a convolution window moves at each step. Stride 2 halves the output size.

T

threshold
The probability above which a photo is flagged, such as damaged. 0.5 is only a default, so a better value is chosen on validation photos from the cost of false flags and misses.
TinyNet
A small convolutional network made of four blocks of conv, BatchNorm, ReLU and max pooling, followed by global average pooling and a linear head. It has 98,436 weights when set to four classes.
ToImage / ToDtype
Two torchvision transforms that convert a photo into a model-ready tensor. `ToImage` makes a uint8 (C, H, W) tensor, and `ToDtype(torch.float32, scale=True)` converts it to floats from 0 to 1; without `scale=True` you get floats from 0 to 255.
torch.export
PyTorch's current way to save a model as a graph that can be reloaded without its class. It is preferred over the deprecated TorchScript for PyTorch-based serving.
TorchScript
An older PyTorch export route (`torch.jit.script`, `torch.jit.trace`) that is now marked deprecated in favor of `torch.export`.
train, validation and test sets
Three separate groups of photos: the training set to learn from, the validation set to compare models and choose settings, and the test set, used once at the end. Here they are fixed folders, split by source.
transfer learning
Starting from a network already trained on another large task and adapting it to your own photos. You give it a new head for your classes and either freeze the backbone and train only the head, or fine-tune the whole network.
transform
A function that takes an image and returns a changed one, such as resized, cropped or converted to a tensor. Each is an object you create once and call like a function, and `torchvision.transforms.v2` is the recommended version.
tv_tensor
A tensor tagged as an image, boxes or mask so that v2 transforms know how to treat it. Wrapping boxes in `tv_tensors.BoundingBoxes` makes them move when the photo is flipped or cropped.

U

uint8
A whole-number type from 0 to 255, the usual pixel type. Its arithmetic wraps around (250 + 10 gives 4), so convert to floats before doing math.

W

weight sharing
Using the same small kernel at every position in the image. A mug handle is therefore detected wherever it appears, with few weights.
WeightedRandomSampler
A sampler that draws each epoch's photos with probabilities you give it, with replacement, so a rare class turns up more often. You don't also pass `shuffle=True` to the DataLoader.
weights enum
A torchvision object, such as `ResNet18_Weights.DEFAULT`, that lists a model's pretrained weights, class names and matching evaluation transforms. It tells you the preprocessing the model expects.
weights_only
An option of `torch.load` that refuses to run code hidden in a file and allows only tensors, numbers, strings, lists and dicts. It is the default since PyTorch 2.6, which is why the checkpoint stores the version with `str()`.