← Writing & notes

FROM THE NOTEBOOK

Deep Learning Algorithms 2: Computer Vision Architectures

Computer Vision is a field of artificial intelligence that trains computers to interpret and understand the visual world. Deep learning has revolutionized this field, moving from handcrafted feature extractors to architectures that can learn hierarchical representations of visual data automatically. This document covers the foundational and advanced neural network architectures that power modern computer vision.

Table of Contents

  1. Convolutional Neural Networks (CNNs): The Foundation
  2. Advanced CNN Architectures: Building Deeper and More Efficient Models
  3. Vision Transformers (ViT): A New Paradigm
  4. Specialized Vision Architectures

1. Convolutional Neural Networks (CNNs): The Foundation

Convolutional Neural Networks (CNNs or ConvNets) are the cornerstone of modern computer vision. Inspired by the human visual cortex, they are specifically designed to process pixel data and are exceptional at tasks like image classification, object detection, and image segmentation.

Core Components and Mathematical Principles

CNNs introduce two key concepts that distinguish them from standard Multi-Layer Perceptrons:

  1. Local Receptive Fields & Parameter Sharing: Instead of connecting every neuron to every neuron in the previous layer, a CNN uses filters (or kernels). Each filter is a small matrix of weights that slides (convolves) over the input image. This filter is responsible for detecting a specific feature (like an edge or a texture). The same filter is used across the entire image (parameter sharing), making the network efficient and allowing it to detect features regardless of their position (translation invariance).

  2. Pooling Layers: After a convolutional layer, a pooling layer (typically Max Pooling) is often used to downsample the feature map. It reduces the spatial dimensions of the data, which decreases the number of parameters and computational complexity, and also helps to make the feature detection more robust to small translations.

A typical CNN architecture consists of a stack of convolutional layers and pooling layers, which act as feature extractors, followed by one or more fully connected layers for classification.

Key Historical Architectures


2. Advanced CNN Architectures

To train even deeper networks and improve efficiency, several advanced architectural innovations have been developed.

ResNet (Residual Network)

ConvNeXt

ConvNeXt is a modern, pure CNN that was designed by "modernizing" a standard ResNet with architectural principles borrowed from Vision Transformers. By systematically adapting components like using depthwise separable convolutions and different activation functions, ConvNeXt achieves the performance of Transformers while maintaining the simplicity and efficiency of CNNs.

Capsule Networks (CapsNets)

Capsule Networks aim to overcome a key limitation of CNNs: their lack of understanding of hierarchical relationships between object parts (e.g., a face has a nose and two eyes in a specific spatial relationship).


3. Vision Transformers (ViT): A New Paradigm

The Vision Transformer (ViT) represents a significant shift in computer vision, applying the highly successful Transformer architecture, originally designed for Natural Language Processing (NLP), directly to images.

How it Works

  1. Image Patching: The ViT model splits an input image into a sequence of fixed-size, non-overlapping patches (e.g., 16x16 pixels).
  2. Patch Embedding: Each patch is flattened into a vector and linearly projected into an "embedding".
  3. Positional Encoding: To retain spatial information, positional encodings are added to the patch embeddings.
  4. Transformer Encoder: The resulting sequence of vectors is fed into a standard Transformer encoder. The encoder uses the self-attention mechanism to weigh the importance of different patches relative to each other, allowing it to model global relationships across the entire image from the very first layer.
  5. Classification Head: A final classification head (a simple MLP) is attached to the output to make the final prediction.

Significance

ViT demonstrated that a pure Transformer architecture, with no convolutions, can achieve state-of-the-art results on image classification, particularly when pre-trained on very large datasets. This has opened up a new direction for research in computer vision.


4. Specialized Vision Architectures

U-Net: For Image Segmentation

The U-Net architecture is a specialized CNN designed for biomedical image segmentation, a task that requires precise localization (predicting a class for every pixel).

How it Works

U-Net's architecture is symmetric and U-shaped:

  1. Contracting Path (Encoder): A standard CNN stack that downsamples the image and captures context, learning the "what" of the image.
  2. Expansive Path (Decoder): This path uses transposed convolutions to upsample the feature maps back to the original image resolution, localizing the features and learning the "where".
  3. Skip Connections: The key innovation of U-Net is the use of skip connections that concatenate feature maps from the encoder with the corresponding feature maps in the decoder. This combines the high-level semantic information from the decoder with the low-level, high-resolution feature information from the encoder, allowing for very precise segmentation.

The U-Net design has become the de-facto standard for many image segmentation tasks and is also the core network used in modern Diffusion Models.

Object Detection Models

Object detection is a task that involves both classifying and locating objects within an image using bounding boxes.

Key Architectures

Neural Radiance Fields (NeRF): For 3D Scene Synthesis

Neural Radiance Fields (NeRF) are a groundbreaking method for creating novel, photorealistic 3D views of a scene from a sparse set of 2D images.

How it Works

A NeRF model represents a 3D scene as a continuous function, implemented as a simple MLP. This network takes a 5D coordinate (3D location (x, y, z) and 2D viewing direction (θ, φ)) as input and outputs a volume density and an RGB color.

To render an image from a new viewpoint, virtual camera rays are cast through the scene. The network is queried at many points along each ray to get the color and density. These values are then integrated using classical volume rendering techniques to compute the final color of the pixel. The result is a stunningly realistic 3D reconstruction.

All writing