Downloads · 30 days
20
21% of all-time downloads
sdoerrich97/stylizing_vit_base_camelyon17wilds
stylizing_vit_base_camelyon17wilds is a image-to-image model from sdoerrich97. Use it when you need one image transformed into another. It is set up for stylizing-vit. The card lists the license as apache-2.0.
This model is the Base variant of Stylizing ViT, trained on the Camelyon17-Wilds (histopathology) dataset with default splits.
Downloads · 30 days
20
21% of all-time downloads
All-time downloads
95
Public
Parameters
111M
884 MB on disk
Likes
0
Public
Click a slice to open those files.
.pth442 MB · 50%
From the Hugging Face model README
This model is the Base variant of Stylizing ViT, trained on the Camelyon17-Wilds (histopathology) dataset with default splits.
Stylizing ViT is 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 (via self-attention) while performing style transfer (via cross-attention), enabling anatomy-preserving instance style transfer for domain generalization in medical imaging.
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 modality-agnostic style augmentation method. It uses a single-encoder Vision Transformer (ViT) architecture to fuse anatomical structure from a content image with stylistic attributes from a reference image.
The primary use case is style transfer for medical images. This model takes a content image (e.g., a specific pathology slide) and a style reference, and generates a new image that retains the anatomical content of the first but adopts the visual style (staining, color distribution) of the second.
Users should valid visually that the anatomical structures (e.g., cell boundaries, tissue architecture) are preserved in the stylized output before using the generated data for training sensitive downstream models.
You can load this model using the stylizing-vit library. Since this model is hosted in its own repository, you can download the weights using huggingface_hub and load them into the model.
The model requires the following input specification:
(B, C, H, W).pip install stylizing-vit
import torch
from stylizing_vit import create_model
# Initialize the model
device = "cuda" if torch.cuda.is_available() else "cpu"
# Load the model with pretrained weights
# This automatically downloads the weights from the Hugging Face Hub
model = create_model(backbone="base", weights="camelyon17wilds", train=False).to(device)
model.eval()
# Apply Style Transfer
# content_img and style_img should be normalized torch tensors of shape (1, 3, 224, 224)
# with torch.no_grad():
# stylized_img = model(content_img, style_img)
``` stylized_img = model(content_img, style_img)
The model is trained to minimize a combination of losses using a frozen VGG19 perceptual network:
vit_base (12 layers, 12 heads, 768 embedding dim)timm.optim.create_optimizer_v2)timm.scheduler.CosineLRScheduler)import torch
from accelerate import Accelerator
from stylizing_vit.model import StylizingViT
# 1. Setup
accelerator = Accelerator()
device = accelerator.device
model = StylizingViT(backbone="base", train=True).to(device)
# Frozen VGG encoder for loss computation
model.vgg_encoder.requires_grad_(False)
model.vgg_encoder.eval()
# Optimized parameters: Encoder + Bottleneck + Post-Process Conv
params = (
list(model.encoder.parameters()) +
list(model.bottleneck.parameters()) +
list(model.post_process_conv.parameters())
)
optimizer = torch.optim.AdamW(params, lr=1e-4) # Example LR
# 2. Training Loop
model.train()
for epoch in range(100):
for batch in train_loader:
# images: (B, C, H, W)
images, _ = batch
images = images.to(device)
# Create style pairs (e.g., by rolling the batch)
style_images = images.roll(shifts=1, dims=0)
# Forward pass returns loss components and reconstructions
# Model internally computes Identity, Consistency, Anatomical, and Style losses
loss_dict, _ = model(images, style_images)
# Total loss is weighted sum (internal to model return or manually summed)
total_loss = loss_dict.total_loss
optimizer.zero_grad()
accelerator.backward(total_loss)
optimizer.step()
import torch
from stylizing_vit import create_model
# Load pre-trained Stylizing ViT
stylizer = create_model(backbone="base", weights="path/to/weights.pth", train=False)
stylizer.eval()
stylizer.requires_grad_(False)
def augment_batch(images):
"""
Augment a batch of images using style transfer.
"""
# Create style reference (e.g., shuffle current batch)
style_reference = images[torch.randperm(images.size(0))]
with torch.no_grad():
# Generate stylized images
# Input images should be normalized
stylized_images = stylizer(images, style_reference)
return stylized_images
# Usage in training loop
# for images, labels in dataloader:
# augmented_images = augment_batch(images)
# # Pass augmented_images to your downstream classifier...
The model is evaluated on:
As reported in the associated ISBI 2026 paper, Stylizing ViT demonstrates improved robustness (up to 13% accuracy gain) over state-of-the-art methods in domain generalization tasks on histopathology and dermatology datasets.
If you use this model in your research, please cite:
@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}
}
For questions or issues, please open an issue in the GitHub repository.