Stylizing ViT: Anatomy-Preserving Instance Style Transfer for Domain Generalization @ ISBI 2026
[Preprint] [Publication] [PyPI] [Pretrained Weights] [Citation]
Overview
Deep learning models in medical image analysis often struggle with generalizability across domains and demographic groups due to data heterogeneity and scarcity. Traditional augmentation improves robustness, but fails under substantial domain shifts. Recent advances in stylistic augmentation enhance domain generalization by varying image styles but fall short in terms of style diversity or by introducing artifacts into the generated images. To address these limitations, we propose Stylizing ViT, a novel Vision Transformer encoder that utilizes weight-shared attention blocks for both self- and cross-attention. This design allows the same attention block to maintain anatomical consistency through self-attention while performing style transfer via cross-attention. We assess the effectiveness of our method for domain generalization by employing it for data augmentation on three distinct image classification tasks in the context of histopathology and dermatology. Results demonstrate an improved robustness (up to 13% accuracy) over the state of the art while generating perceptually convincing images without artifacts. Additionally, we show that Stylizing ViT is effective beyond training, achieving a 17% performance improvement during inference when used for test-time augmentation.
Left: Overview of how Stylizing ViT is used to improve domain generalization during training and inference. During training, it generates stylistically diverse but anatomically consistent images, encouraging downstream classifiers to learn structure-aware representations. At test time, it is used to align unseen input styles with the training distribution, thereby mitigating style-induced domain shifts.
Right: Illustration of the underlying method. The input image pair ($I$, $S$) is processed by the encoder that fuses the anatomical structure of $I$ with the style characteristics of $S$ using cross-attention. Subsequently the stylized image $T$ is reconstructed through a two-layer MLP, a dot-product operation, and a convolutional layer. A frozen VGG19 encoder is used during training to compute perceptual losses.
Key Contributions
- A modality-agnostic style augmentation method for domain generalization.
- A novel ViT design enabling weight sharing within a unified attention block for both self- and cross-attention information fusion, termed Stylizing ViT.
- Applicability for test-time augmentation (TTA) to enhance generalization to new, unseen domains during inference.
- Comprehensive experiments across three medical imaging datasets, demonstrating consistent improvements in style transfer quality, state-of-the-art classification performance (up to +9% accuracy over prior best), and significant gains from TTA.
Installation and Requirements
From PyPI
pip install stylizing-vit
From Source
Clone this repository and install it in editable mode:
git clone https://github.com/sdoerrich97/stylizing-vit.git
cd stylizing-vit
pip install -e .
To install training dependencies (like wandb, accelerate):
pip install -e ".[train]"
Quick Start
Inference (Style Transfer)
You can easily load a pre-trained model and perform style transfer on your images.
import torch
from stylizing_vit import create_model, resize_image
# 1. Initialize Model & Load Pretrained Weights
# Weights are automatically downloaded from Hugging Face
device = "cuda" if torch.cuda.is_available() else "cpu"
model = create_model(backbone="base", weights="camelyon17wilds", train=False).to(device)
model.eval()
# 3. Stylize
# Assume content_img and style_img are normalized tensors (1, 3, 224, 224)
with torch.no_grad():
stylized_img = model(content_img, style_img)
See examples/inference_style_transfer.ipynb for a complete visual guide using the PathMNIST dataset.
Training
The package exposes the core model and loss components, allowing you to integrate StylizingViT into your own training loops.
See examples/training_demo.ipynb for a minimal training example.
Model Zoo
We provide pretrained weights for the following configurations on our Hugging Face Hub.
| Pathology | Dataset | Model Size | Weights Identifier |
|---|---|---|---|
| Histopathology | Camelyon17-Wilds | base, small, tiny |
camelyon17wilds |
| Epithelium-Stroma | base, small, tiny |
epistr |
|
| Dermatology | Fitzpatrick17k (Train: 12 / Val: 34 / Test: 56) | base, small, tiny |
fitzpatrick17k_12_34_56 |
| Fitzpatrick17k (Train: 56 / Val: 34 / Test: 12) | base, small, tiny |
fitzpatrick17k_65_43_21 |
|
| DDI (Train: 12 / Val: 34 / Test: 56) | base, small, tiny |
ddi_12_34_56 |
|
| DDI (Train: 56 / Val: 34 / Test: 12) | base, small, tiny |
ddi_65_43_21 |
|
| Laparoscopy | Cholec80 | base, small, tiny |
cholec80 |
You can load these directly using create_model(backbone="<size>", weights="<Weights Identifier>"). For example:
model = create_model(backbone="base", weights="camelyon17wilds", train=False)
Project Structure 📁
stylizing_vit/: Core library package.model/: Model architecture definition.loss/: Loss functions.main.py: High-level utilities and weight loading.util.py: Image processing utilities.
examples/: Jupyter notebooks demonstrating usage.experiments/: Experiments used within the paper.
Results
Qualitative results on training image pairs
Citation
If you use this code in your research, please cite: TBD
@article{doerrich2026stylizingvit,
title={Stylizing ViT: Anatomy-Preserving Instance Style Transfer for Domain Generalization},
author={Sebastian Doerrich and Francesco Di Salvo and Jonas Alle and Christian Ledig},
year={2026},
eprint={2601.17586},
archivePrefix={arXiv},
primaryClass={cs.CV}
}
License
Apache-2.0
Changelog
v1.0.0 (2026-01-27)
- Fix: Updated model weight loading to support and prioritize
.safetensorsfiles from Hugging Face, resolvingtorch.loadsecurity warnings and compatibility issues. - New: Added
.safetensorsdependency to installation requirements. - Docs: Added comprehensive examples for Inference, Training, and Augmentation.
v0.1.0 (2026-01-27)
- Initial release accompanying the paper "Stylizing ViT: Anatomy-Preserving Instance Style Transfer for Domain Generalization".
Metadata
Release files for stylizing-vit 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| stylizing_vit-1.0.0.tar.gz | 25.2 kB | Without provenance | Details for stylizing_vit-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| stylizing_vit-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for stylizing_vit-1.0.0-py3-none-any.whl |
Total release size: 51.4 kB
Release files / stylizing_vit-1.0.0.tar.gz
| Download URL | stylizing_vit-1.0.0.tar.gz |
|---|---|
| Size | 25.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
11bcec288c49da7bee50f7278dace062ac0eb3ebb80eed576a497bc4c5a6b7b1
|
|
BLAKE2b-256 checksum How to use checksums |
52546a25d94cead95592113cbb36d5708150342c00e2bdc6b3808b808bfc0553
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.4
|
Release files / stylizing_vit-1.0.0-py3-none-any.whl
| Download URL | stylizing_vit-1.0.0-py3-none-any.whl |
|---|---|
| Size | 26.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
37cb3c2b5e42dcc418612df36576b6f6e247067154188d1e5aa5d7015642a391
|
|
BLAKE2b-256 checksum How to use checksums |
aed3874d95ac27669b7a38ec611b0cb81b2ede7879aaf248e1d5785b3c894f91
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.4
|
Security for stylizing-vit 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.