Lesson 4 of 13

Vision Models

How AI sees, understands, and interprets images and video

What Are Vision Models?

Vision models are AI systems designed to understand, analyze, and process visual data - images, video frames, medical scans, satellite imagery, and more. They enable machines to perform tasks that previously required human eyesight: recognizing objects, reading text in photos, detecting anomalies, and even generating new images.

Computer vision has progressed from hand-crafted feature detectors in the 2000s, through deep convolutional neural networks in the 2010s, to transformer-based architectures that now achieve superhuman performance on many benchmarks. Today's vision models can identify thousands of object categories, segment every pixel in an image, and understand spatial relationships between objects.

Key Vision Tasks

Image Classification

The most fundamental vision task: given an image, assign it a label. "This is a dog." "This is a chest X-ray showing pneumonia." Classification models output a probability distribution over predefined categories. Modern classifiers achieve over 90% accuracy on ImageNet's 1,000 categories.

Object Detection

Goes beyond classification by identifying where objects are in an image. Object detection models output bounding boxes - rectangles around each detected object - along with class labels and confidence scores. This is essential for autonomous driving, security cameras, and inventory management.

Semantic Segmentation

Assigns a class label to every pixel in an image. Where object detection draws boxes, segmentation creates precise masks. Instance segmentation further distinguishes between individual objects of the same class (e.g., separating three different people in a crowd).

Image Generation

Models like Stable Diffusion, DALL-E 3, and Midjourney create new images from text descriptions or modify existing images. While not traditional "vision" in the perception sense, these models deeply understand visual concepts.

Optical Character Recognition (OCR)

Extracting text from images - scanned documents, street signs, receipts, handwritten notes. Modern OCR models handle multiple languages, unusual fonts, and distorted text with high accuracy.

Architecture Evolution

Convolutional Neural Networks (CNNs)

CNNs dominated computer vision from 2012 to 2020. They use convolutional filters that slide across the image to detect patterns - edges, textures, shapes - building increasingly abstract representations through successive layers.

  • ResNet (2015): Introduced residual connections enabling networks with 50-152+ layers. Still widely used as a backbone.
  • EfficientNet (2019): Systematically scaled network depth, width, and resolution for optimal accuracy-to-compute ratio.
  • MobileNet: Lightweight architecture designed for mobile and edge devices with depthwise separable convolutions.

Vision Transformers (ViT)

Starting in 2020, the transformer architecture - originally designed for NLP - was adapted for vision. Vision Transformers split images into patches (e.g., 16x16 pixels), treat each patch as a "token," and process them using self-attention mechanisms.

  • ViT (2020): The original Vision Transformer, proving transformers can match or beat CNNs on image classification when trained on enough data.
  • DINOv2 (2023): Meta's self-supervised ViT that learns powerful visual features without any labels. Excellent as a general-purpose visual backbone.
  • SAM / SAM 2 (2023-2024): Meta's Segment Anything Model - a foundation model for image and video segmentation that can segment any object with minimal prompts.

Major Vision Models Compared

Model Primary Task Speed Accuracy Best For
YOLOv9 Object Detection Very Fast High Real-time detection, edge deployment
YOLOv8 Detection + Segmentation Very Fast High Production systems, easy API
SAM 2 Segmentation Medium Very High Interactive segmentation, video
CLIP Classification + Retrieval Fast High Zero-shot classification, image search
Florence-2 Multi-task Vision Medium Very High Captioning, detection, OCR combined
Grounding DINO Open-set Detection Medium High Detecting objects from text descriptions
DINOv2 Feature Extraction Fast Very High Visual backbone, transfer learning
PaLI Vision-Language Slow Very High Visual Q&A, captioning, OCR
EfficientNet-B7 Classification Medium Very High Accurate classification, transfer learning

Object Detection vs Classification vs Segmentation

These three tasks form a hierarchy of visual understanding. Understanding the difference helps you choose the right approach:

Classification: "There is a cat in this image." One label for the entire image. Simplest and fastest. Use when you only need to know what is in the image.
Object Detection: "There is a cat at coordinates (120, 80, 340, 290) and a dog at (400, 100, 600, 350)." Bounding boxes around each object. Use when you need to know where objects are.
Segmentation: "These exact pixels belong to the cat, these to the dog, and the rest is background." Pixel-level precision. Use when you need exact object boundaries - medical imaging, autonomous driving, photo editing.

Each level adds computational cost. Classification runs in under 1ms; segmentation may take 50-200ms per image depending on the model and hardware. Choose the minimal level of detail your application actually requires.

Use Cases

Autonomous Vehicles

Self-driving cars use object detection to identify pedestrians, vehicles, traffic signs, and lane markings in real time. Models must process multiple camera feeds at 30+ FPS with extremely high reliability - a missed detection could have fatal consequences.

Medical Imaging

Vision models analyze X-rays, CT scans, MRIs, and pathology slides to detect tumors, fractures, retinal diseases, and other conditions. AI-assisted diagnosis helps radiologists catch findings they might miss and prioritize urgent cases.

Manufacturing Quality Assurance

Cameras on assembly lines use vision models to inspect products for defects - scratches, misalignment, missing components. Automated inspection is faster and more consistent than human inspectors, running 24/7 without fatigue.

Security and Surveillance

Object detection identifies suspicious objects (unattended bags), tracks individuals across camera feeds, detects intrusions in restricted areas, and reads license plates. Modern systems process hundreds of camera streams simultaneously.

Retail and E-commerce

Visual search lets shoppers photograph products and find similar items to buy. Shelf monitoring detects out-of-stock products. Automated checkout systems use vision to identify products without barcodes.

Code Example: YOLO Object Detection

Here is how to run object detection using the Ultralytics YOLOv8 library in just a few lines of Python:

Python
from ultralytics import YOLO

# Load a pretrained YOLOv8 model
model = YOLO("yolov8n.pt")  # 'n' = nano (fastest), also s, m, l, x

# Run detection on an image
results = model("street_scene.jpg")

# Process results
for result in results:
    boxes = result.boxes
    for box in boxes:
        # Get bounding box coordinates
        x1, y1, x2, y2 = box.xyxy[0].tolist()

        # Get class name and confidence
        cls_id = int(box.cls[0])
        class_name = model.names[cls_id]
        confidence = float(box.conf[0])

        print(f"Detected: {class_name} ({confidence:.2f})")
        print(f"  Location: ({x1:.0f}, {y1:.0f}) to ({x2:.0f}, {y2:.0f})")

# Save annotated image with bounding boxes drawn
results[0].save("detected_output.jpg")

# Run on video (processes frame by frame)
video_results = model("traffic_video.mp4", stream=True)
for frame_result in video_results:
    # Process each frame
    print(f"Frame detections: {len(frame_result.boxes)}")
Model sizes: YOLOv8 comes in five sizes - nano (n), small (s), medium (m), large (l), and extra-large (x). Nano runs at 600+ FPS on a GPU with ~3.2M parameters. Extra-large achieves the highest accuracy at ~60 FPS with ~68M parameters. Choose based on your speed vs accuracy requirements.

Transfer Learning for Vision

You rarely need to train a vision model from scratch. Transfer learning lets you take a model pretrained on millions of images and fine-tune it on your specific dataset with as few as 100-1,000 labeled images.

The process works because early layers in vision models learn universal features (edges, textures, colors) while later layers learn task-specific features. By freezing early layers and training only the final layers, you get a high-quality model with minimal data and compute.

Python
# Fine-tune YOLOv8 on a custom dataset
from ultralytics import YOLO

model = YOLO("yolov8s.pt")  # Start from pretrained weights

# Train on your custom dataset
# data.yaml defines your classes and image paths
results = model.train(
    data="my_dataset/data.yaml",
    epochs=50,
    imgsz=640,
    batch=16,
    patience=10,  # Early stopping
    device="cuda"
)

# Evaluate on validation set
metrics = model.val()
print(f"mAP50: {metrics.box.map50:.4f}")
print(f"mAP50-95: {metrics.box.map:.4f}")

Transfer learning dramatically reduces the data, time, and cost required to build production vision systems. Most real-world applications use transfer learning rather than training from scratch.

Summary

  • Vision models enable AI to understand images and video through classification, detection, segmentation, and generation.
  • Architectures have evolved from CNNs (ResNet, EfficientNet) to Vision Transformers (ViT, DINOv2, SAM).
  • YOLO remains the gold standard for real-time object detection; SAM 2 leads in segmentation; CLIP enables zero-shot classification.
  • Choose the minimum task complexity your application needs: classification < detection < segmentation.
  • Transfer learning lets you adapt pretrained models to custom domains with minimal labeled data.
  • Key applications include autonomous vehicles, medical imaging, manufacturing QA, security, and retail.

Ready to Go Deeper?

Live instructor-led courses from our partners. Affiliate disclosure.