



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Vision Transformers (ViTs) are a class of deep learning architectures that adapt the Transformer model , originally developed for natural language processing (NLP), to computer vision tasks. Instead of relying on convolutional operations to extract local spatial features, ViTs represent an image as a sequence of fixed-size patches , which are linearly embedded and processed using self-attention mechanisms. This allows ViTs to model global dependencies across the entire image from early layers, enabling effective learning of long-range relationships and complex visual patterns. Since their introduction by Dosovitskiy et al. ( 2020 ), Vision Transformers have demonstrated competitive and often superior performance to CNNs on large-scale vision tasks such as image classification, object detection, and semantic segmentation, particularly when trained on large datasets. Key Features of Vision Transformers
1. Patch-Based Image Representation - An input image is divided into non-overlapping patches (e.g., 16×16 pixels). - Each patch is flattened and projected into a fixed-dimensional embedding space. - This converts the image into a sequence similar to word tokens in NLP. 2. Self-Attention for Global Context Modeling - ViTs use multi-head self-attention (MHSA) to capture relationships between all image patches simultaneously. - Enables modeling of long-range dependencies without increasing receptive field depth, unlike CNNs. 3. Positional Encoding - Since Transformers lack inherent spatial inductive bias, positional embeddings are added to patch embeddings. - Preserves spatial information about patch locations within the image. 4. Scalability with Data and Model Size - ViTs scale effectively with large datasets and deeper architectures. - Performance improves significantly with increased training data and model capacity.
5. Unified Architecture Across Vision Tasks - The same ViT backbone can be adapted for multiple tasks: o Image classification o Object detection o Semantic segmentation - Task-specific heads are added with minimal architectural changes. 6. Reduced Inductive Bias Compared to CNNs - ViTs do not assume locality or translation invariance by default. - This flexibility allows learning of more general and complex visual patterns, especially in diverse datasets. 7. Compatibility with Hybrid and Hierarchical Models - ViTs can be combined with CNNs (hybrid CNN–Transformer models) to leverage both local feature extraction and global context modeling. - Hierarchical ViTs (e.g., Swin Transformer) introduce multi-scale representations similar to CNN feature pyramids. 8. Strong Transfer Learning Capability - Pretrained ViTs can be fine-tuned effectively for downstream vision tasks. - Often outperform CNNs when transferred across domains, given sufficient pretraining data. Summary Table Feature Description Patch Embedding Converts image into token sequence Self-Attention Captures global dependencies Positional Encoding Maintains spatial structure Scalability Improves with larger data and models
Theoretical Comparison: Vision Transformers vs. Convolutional Neural Networks
1. Fundamental Architectural Principles Convolutional Neural Networks (CNNs) CNNs are built on convolution operations , which apply learnable kernels locally across an image. This introduces strong inductive biases , such as: - Locality: Nearby pixels are more related than distant ones. - Translation equivariance: Features shift consistently with input translations. These biases make CNNs highly efficient and effective for vision tasks with limited training data. Vision Transformers (ViTs) Vision Transformers replace convolution with self-attention mechanisms , processing an image as a sequence of patch embeddings. ViTs have minimal inductive bias and rely on: - Global self-attention: Every patch can attend to every other patch. - Learned spatial structure: Position information is encoded explicitly. This makes ViTs more flexible but more data-hungry. 2. Mathematical Perspective CNN Operation A convolution layer computes: [ \mathbf{y} {i,j} = \sum {m,n} \mathbf{W} {m,n} \cdot \mathbf{x} {i+m,j+n} ] where: - ( \mathbf{W} ) is a local kernel, - ( \mathbf{x} ) is the input feature map. Receptive fields grow gradually with depth. ViT Self-Attention Self-attention computes: [ \text{Attention}(Q, K, V) = \text{softmax}\left(\frac{QK^\top}{\sqrt{d}}\right)V ] where:
Criterion CNNs ViTs Theoretical bias Strong, domain-specific Minimal, flexible Learning long-range dependencies Difficult Natural Data requirement Moderate Large Architectural flexibility Moderate High
10. Summary of Theoretical Trade-offs Dimension CNNs Vision Transformers Core operation Convolution Self-attention Inductive bias Strong Weak Global context Limited Excellent Data efficiency High Lower Computational scaling Linear Quadratic Flexibility Moderate High From a theoretical standpoint, CNNs encode strong visual priors that make them efficient and data- efficient for pattern recognition, while Vision Transformers trade inductive bias for flexibility , enabling superior global reasoning when trained on large-scale datasets. Consequently, hybrid CNN– Transformer architectures are emerging as a promising direction to combine the theoretical strengths of both paradigms.