Abstract: Position Embeddings (PEs), an arguably indispensable component in Vision Transformers (ViTs), have been shown to improve the performance of ViTs on many vision tasks. However, PEs have a potentially high risk of privacy leakage since the spatial information of the input patches is exposed. This caveat naturally raises a series of interesting questions about the impact of PEs on the accuracy, privacy, prediction consistency, etc. To tackle these issues, we propose a Masked Jigsaw Puzzle (MJP) position embedding method. In particular, MJP first shuffles the selected patches via our block-wise random jigsaw puzzle shuffle algorithm, and their corresponding PEs are occluded. Meanwhile, for the non-occluded patches, the PEs remain the original ones but their spatial relation is strengthened via our dense absolute localization regressor. The experimental results reveal that 1) PEs explicitly encode the 2D spatial relationship and lead to severe privacy leakage problems under gradient inversion attack; 2) Training ViTs with the naively shuffled patches can alleviate the problem, but it harms the accuracy; 3) Under a certain shuffle ratio, the proposed MJP not only boosts the performance and robustness on large-scale datasets (i.e., ImageNet-1K and ImageNet-C, -A/O) but also improves the privacy preservation ability under typical gradient attacks by a large margin.
The Spatial Privacy Paradox
Vision Transformers (ViTs) have revolutionized computer vision by applying the self-attention mechanism to image patches. However, unlike Convolutional Neural Networks (CNNs), ViTs are inherently "permutation-invariant"—they treat an image as an unordered bag of patches. To restore spatial context, researchers use Position Embeddings (PEs), which add coordinate information to each patch.
While PEs are critical for accuracy, they create a significant privacy vulnerability. In distributed settings like federated learning, an attacker can intercept model gradients and use the structured nature of PEs to reassemble the original image patches. This "gradient inversion attack" effectively turns the model's internal spatial map into a blueprint for reconstructing private data.
Methods: Masked Jigsaw Puzzle (MJP)
To resolve the conflict between spatial awareness and privacy, we propose Masked Jigsaw Puzzle (MJP). This method strategically disrupts the rigid link between image content and its coordinate map during training.
MJP consists of three core mechanisms:
- Block-wise Random Jigsaw Shuffle: A portion of image patches (defined by a ratio $\gamma$) is shuffled within local blocks. This forces the model to learn robust content features rather than relying on a fixed grid.
- Position Occlusion (UNK): For shuffled patches, the specific position embeddings are hidden and replaced with a shared
unknownembedding. This "breaks the chain" that attackers use to map gradients back to specific locations. - Dense Absolute Localization (DAL): To maintain accuracy, a self-supervised regressor is used for the unshuffled patches. The model must predict their exact 2D coordinates, strengthening the spatial prior without exposing the shuffled regions.
Key Insights: Visualizing the "Map"
By applying dimensionality reduction techniques like UMAP and PCA to the learned position embeddings, we can visually confirm the problem. Standard PEs organize themselves into a nearly perfect 2D grid, essentially providing a "GPS" for attackers to navigate the model's gradients.
MJP addresses this by introducing "confusion" into this map. By using the unknown embedding for shuffled patches, the method creates a many-to-one mapping that prevents attackers from uniquely identifying patch locations.
Experimental Results
Our evaluation across ImageNet-1K and various robustness benchmarks (ImageNet-C, -A, -O) demonstrates that MJP is not just a privacy tool, but a performance enhancer:
- Accuracy Boost: On DeiT-S, MJP improved Top-1 accuracy from 79.8% to 80.5%, showing that strategic shuffling acts as a powerful data augmentation.
- Prediction Consistency: Standard ViTs are brittle; shuffling input patches at test time often causes predictions to fail. MJP-trained models maintained a consistency of 82.9%, compared to 64.3% for standard models.
- Privacy Preservation: Under state-of-the-art gradient inversion attacks, MJP increased reconstruction error (MSE) by nearly 3x, effectively reducing recovered images to unrecognizable noise.
- Robustness: MJP significantly improved the model's ability to handle corruptions like blur or noise, lowering the Mean Corruption Error (mCE) on ImageNet-C from 54.6 to 40.78.
Conclusion
Masked Jigsaw Puzzle (MJP) demonstrates that privacy and performance are not mutually exclusive in Vision Transformers. By breaking the explicit spatial chain of position embeddings and replacing it with a more flexible, self-supervised spatial prior, MJP creates models that are more accurate, more robust, and significantly harder to exploit via gradient attacks.
Summary updated