MSPE: Multi-Scale Patch Embedding Prompts Vision Transformers to Any Resolution
Introduction: The Resolution-Lock Problem
Vision Transformers (ViTs) have revolutionized computer vision, yet they remain largely "resolution-locked." Standard training pipelines resize images to a fixed square (typically 224x224) and partition them into a static grid of patches. When these models encounter real-world images with varying resolutions or aspect ratios, performance often collapses. Common workarounds—like resizing (which introduces artifacts) or changing patch sizes (which shifts feature distributions)—fail to maintain the integrity of the Transformer encoder's learned representations.
Methodology: Multi-Scale Patch Embedding (MSPE)
To address this, we propose Multi-Scale Patch Embedding (MSPE), a lightweight, plug-and-play modification to the ViT architecture. MSPE replaces the standard fixed patch embedding layer with a more flexible "entryway" composed of:
- Multiple Patching Kernels: Instead of a single convolutional kernel, MSPE employs $K$ sets of kernels (optimally $K=4$), each specialized for a different resolution range.
- Adaptive PI-Resize: To accommodate any arbitrary resolution $(h, w)$, MSPE uses a Pseudo-inverse (PI) resize technique. This mathematically adjusts kernel weights on the fly to match the input dimensions and aspect ratio perfectly.
- Efficient Training: The core Transformer encoder remains frozen. Only the new patch embedding parameters are trained over just five epochs of mixed-resolution data. This process is remarkably fast, requiring only about 3 hours on standard hardware compared to the 50+ hours needed for full-model retraining methods like ResFormer.
- Dynamic Position Embeddings: Standard position embeddings are resampled via bilinear interpolation to match the varying token counts generated by different input scales.
Key Results and Performance
MSPE demonstrates significant robustness across a wide range of scales and aspect ratios.
As shown in the figure above, MSPE dominates in low-resolution scenarios. At a tiny 28x28 resolution, a vanilla ViT-B achieves only 8.52% accuracy, while MSPE boosts this to 56.41%. Crucially, MSPE also maintains high-resolution stability, matching or exceeding vanilla performance at 448x448 without requiring a dedicated high-res model. Furthermore, MSPE handles extreme aspect ratios (e.g., 128x896) where vanilla models typically fail.
Key Insights: Task Loss vs. Embedding Similarity
A pivotal finding of this work is the critique of similarity-based adaptation methods like FlexiViT. While FlexiViT attempts to force patch embeddings at different resolutions to look like the original 224x224 embeddings, MSPE focuses solely on optimizing the actual task loss (e.g., classification accuracy).
The analysis in the figure above reveals that high embedding similarity does not necessarily correlate with high performance. By allowing the embedding layer to adapt more freely to the task, MSPE enables the frozen Transformer encoder to process multi-scale features more effectively than methods constrained by similarity targets.
Conclusion
MSPE provides a highly efficient and versatile solution for prompting off-the-shelf Vision Transformers to handle any resolution. By focusing on a learnable, adaptive embedding layer and freezing the encoder, MSPE achieves state-of-the-art performance on low-resolution and non-square inputs with minimal training overhead. This "plug-and-play" approach makes it an ideal candidate for deploying ViTs in diverse real-world environments.
Summary updated