The Problem Swin Transformer Solves
The biggest challenge with using standard Transformers for images is the math. Standard self-attention compares every single pixel to every…
The Problem Swin Transformer Solves
The biggest challenge with using standard Transformers for images is the math. Standard self-attention compares every single pixel to every other pixel, causing computational costs to quadratically (O(N²)) as image resolution grows. The Swin Transformer fixes this by introducing a localized, hierarchical approach.

Source Image
This does not replace CNNs or full transformers; instead, it bridges the two designs using a controlled attention mechanism.
Core Problem in Vision ML
All modern vision architectures are constrained by the computation cost O(N²), where (N) is the number of image patches.
For high-resolution images:
- (N) becomes large
- computation becomes impractical
- memory usage explodes
So every architecture is trying to answer:
How do we model global relationships without paying full global cost?
Baseline systems Swin relates to
Convolutional Neural Networks (CNNs)
CNNs solve vision using:
- fixed local receptive fields
- weight sharing
- hierarchical downsampling
What CNNs do well:
- Efficient computation (linear scaling)
- Strong spatial inductive bias
- Works well on limited data
Limitation:
- Global interaction is indirect
- Long-range dependencies require deep stacking
CNNs assume locality as a hard constraint.
Residual Networks
ResNet improves:
- gradient flow
- trainability of deep CNNs
But it does not change:
- locality structure
- convolutional bias
ResNet solves optimization, not representation limitations.
Vision Transformers (ViT)
ViT changes the paradigm:
- image → patch tokens
- full self-attention across all tokens
Strengths:
- global context from first layer
- flexible interactions
Weakness:
- quadratic cost
- weak inductive bias
- high data requirements
ViT removes structure instead of managing it.
Swin Transformer
Swin does not remove global attention. It just restricts it.
It introduces two mechanisms:
Window-based self-attention (W-MSA):
- Image is divided into fixed windows
- Self-attention is computed inside each window only
This changes complexity:
- ViT: O(N²),
- Swin: O(NM²)
Where:
(M) = window size (constant) This focuses on local attention per layer.
Shifted window attention (SW-MSA)
This shifts window boundaries, which creates:
- cross-window interaction over layers
- gradual information mixing
It’s not a graph-based global connectivity, neither instant global reasoning
Instead, it’s iterative spatial communication.
Hierarchical structure
Swin uses patch merging, which:
- combines neighboring tokens
- reduces resolution
- increases feature dimension
This is NOT deterministic downsampling in token space similar in effect to CNN stride, but not adaptive
Comparison of locality behavior
CNN vs Swin
CNN:
- fixed spatial kernel
- same operation everywhere
Swin:
- fixed window structure
- dynamic attention inside window
Swin does NOT “learn locality from scratch”. It uses fixed locality with learned weighting inside it.
ViT vs Swin
ViT:
- global attention everywhere
- immediate full connectivity
- quadratic cost
Swin
- local attention + shifted partitions
- global behavior appears over depth
Swin does NOT match ViT’s global reasoning per layer.
Instead, swin approximates global context through depth-wise propagation of local interactions.
Swin vs YOLO
YOLO (You Only Look Once):
YOLO is optimized for:
- real-time inference
- single-pass prediction
- latency constraints
Swin is optimized for:
- representation quality
- hierarchical feature learning
- backbone generalization
They are not competitors.
YOLO = execution model (fast prediction head)
Swin = representation backbone (feature construction)
What Swin actually contributes
The real contribution is not attention itself.
It is:
Replace full self-attention with structured, alternating local attention that still allows information flow across the entire image over multiple layers.
This introduces:
- controlled sparsity in attention
- linear scaling with image size
- hierarchical feature formation
Correct complexity interpretation
Swin attention cost: O(NM²),
Where:
(N): number of patches
(M): window size
Which is:
- linear in image size
- quadratic only inside small fixed windows
- Not “near-global efficiency”, but: globally scalable local computation
Conclusion
Vision architectures sit on three axes:
1. Connectivity
CNN: local fixed
ViT: fully global
Swin: local + structured mixing
2. Inductive bias
CNN: strong fixed bias
ViT: weak bias
Swin: moderate structured bias
3. Scalability
CNN: efficient
ViT: expensive at scale
Swin: balanced
Swin Transformer is best understood as:
A hierarchical vision transformer that replaces global self-attention with alternating local window attention and shifted partitions, allowinf scalable computation while gradually propagating information across the entire image.
It is not globally connected attention, nore learned locality like CNNs, and neither equivalent to ViT global reasoning
It is a structured approximation of global dependency using constrained local computation
메타데이터
- post_id
- f9203cb6a4e9
- slug
- the-problem-swin-transformer-solves-f9203cb6a4e9
- url
- https://medium.com/@ml-point/the-problem-swin-transformer-solves-f9203cb6a4e9
- canonical_url
- https://medium.com/@ml-point/the-problem-swin-transformer-solves-f9203cb6a4e9
- author_url
- https://medium.com/@ml-point
- status
- ok
- fetched_at
- 2026-06-23 06:34:20