File size: 1,716 Bytes
8a0616c
cea56d6
 
 
 
8a0616c
cea56d6
8a0616c
cea56d6
 
 
8a0616c
 
cea56d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
---
title: PolypSteer
emoji: 🔬
colorFrom: pink
colorTo: yellow
sdk: gradio
sdk_version: 6.15.1
app_file: app.py
short_description: Training-free activation steering for endoscopic synthesis
python_version: "3.12"
startup_duration_timeout: 1h
---

# PolypSteer: Counterfactual Endoscopic Synthesis

This Space demonstrates **PolypSteer** (a.k.a. MedSteer), a training-free activation
steering method for endoscopic image synthesis. It loads a
[PixArt-α](https://huggingface.co/PixArt-alpha/PixArt-XL-2-512x512) model fine-tuned
with LoRA on the [Kvasir](https://datasets.simula.no/kvasir/) endoscopy dataset
(LoRA adapters from [phamtrongthang/medsteer](https://huggingface.co/phamtrongthang/medsteer)),
then steers the cross-attention activations of the diffusion transformer at inference
time to generate counterfactual images — the same scene with pathological features
suppressed.

## How it works

1. **Direction vectors** are precomputed at startup by capturing cross-attention
   activations for two concept prompts (e.g. "dyed lifted polyps" vs "normal cecum")
   and computing the mean-difference direction per denoising step and transformer block.
2. **Baseline generation** produces the image the fine-tuned model would normally
   generate for a given prompt.
3. **Steered generation** suppresses the component of each cross-attention output
   that aligns with the concept direction, producing a counterfactual image where
   the pathological finding is reduced.

## Paper

[PolypSteer: Counterfactual Endoscopic Synthesis via Training-Free Activation Steering](https://huggingface.co/papers/2603.07066)

## License

CC BY-NC 4.0 (model and code). Free for academic and non-commercial research use.