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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
<div align="center">

# TherA: Thermal-Aware Visual-Language Prompting for<br>Controllable RGB-to-Thermal Infrared Translation

[**Dong-Guw Lee**](https://scholar.google.com/citations?user=u6VDnlgAAAAJ&hl=ko)<sup>1*</sup>&emsp;
[**Tai Hyoung Rhee**](https://scholar.google.com/citations?user=PF8EfdYAAAAJ&hl=en&oi=ao)<sup>1*</sup>&emsp;
[**Hyunsoo Jang**](https://rpm.snu.ac.kr)<sup>1</sup><br>
[**Young-Sik Shin**](https://scholar.google.com/citations?user=gGfBRawAAAAJ&hl=en&oi=ao)<sup>2</sup>&emsp;
[**Ukcheol Shin**](https://scholar.google.com/citations?user=ZvxI80EAAAAJ&hl=ko&oi=ao)<sup>3</sup>&emsp;
[**Ayoung Kim**](https://ayoungk.github.io/)<sup>1&dagger;</sup>

<sup>1</sup>Seoul National University&emsp;
<sup>2</sup>Kyungpook National University&emsp;
<sup>3</sup>KENTECH  
<sup>*</sup> Equal Contribution&emsp;
<sup>&dagger;</sup> Corresponding Author

**CVPR 2026**

[![Project Page](https://img.shields.io/badge/Project_Page-TherA-blue)](https://donkeymouse.github.io/thera_cvpr26/)
[![arXiv](https://img.shields.io/badge/arXiv-2602.19430-b31b1b.svg)](https://arxiv.org/abs/2602.19430)
[![GitHub](https://img.shields.io/badge/GitHub-donkeymouse%2FTherA-black)](https://github.com/donkeymouse/TherA)
[![Weights](https://img.shields.io/badge/HuggingFace-Weights-yellow)](https://huggingface.co/donkeymouse/TherA/tree/main)
[![Dataset](https://img.shields.io/badge/HuggingFace-R2T2-orange)](https://huggingface.co/datasets/donkeymouse/TherA-R2T2)
[![Docker](https://img.shields.io/badge/Docker-donkeymouse%2Fthera-2496ED)](https://hub.docker.com/r/donkeymouse/thera)

</div>

<p align="center">
  <img src="assets/method.png" width="90%" alt="TherA method overview">
</p>


---

## News

- **2026-04-03**: TherA github repo opening
- **2026-05-22**: TherA inference code and R2T2 dataset release.

---

## Overview

**TherA** is a controllable RGB-to-thermal infrared translation framework. Given an RGB image, TherA synthesizes a long-wave thermal infrared image using a latent-diffusion translator conditioned on thermal-aware visual-language features.

TherA is designed for:

- **RGB β†’ TIR translation** for thermal perception research.
- **Thermal-aware VLM conditioning** using LLaVA hidden-state features.
- **Scene- and object-level controllability** across weather, time of day, and object state.
- **Reference-cache inference**, allowing deployment without loading LLaVA at runtime.


<div align="center">
  <a href="https://www.youtube.com/watch?v=X60UxjGKQkg">
    <img src="https://img.youtube.com/vi/X60UxjGKQkg/0.jpg" alt="TherA demo video" width="720">
  </a>
</div>


---

## Key Idea

TherA does **not** condition directly on raw text during diffusion inference. Instead, it uses a **4096-dimensional LLaVA hidden state**, either:

1. loaded from a precomputed `.pt` reference cache, or
2. extracted on the fly using LLaVA.



For resource limited environments, we recommend **reference-cache mode**. This mode uses precomputed LLaVA features such as `SUNNY.pt`, `CLOUDY.pt`, `RAINY.pt`, or `NIGHT.pt`, and therefore does **not** require loading LLaVA weights at runtime. An alternative would be to compute pre-computed LLaVA feature first followed by inferencing with reference-cache mode (upcoming feature). 

---
## Repository Layout

```text
TherA/
β”œβ”€β”€ infer_custom.py             # Batch RGB β†’ TIR inference on a folder
β”œβ”€β”€ infer_example_guided.py     # Single-image / example-guided inference
β”œβ”€β”€ infer_palette.sh        # Run multiple weather/style palettes
β”œβ”€β”€ lavi_ip2p/                  # UNet 8-channel + adapter wrapper
β”œβ”€β”€ LaVi-Bridge/modules/        # TextAdapter architecture
β”œβ”€β”€ llava/                      # LLaVA code, only needed for on-the-fly mode
β”œβ”€β”€ thera_paths.py              # Default local weight paths
β”œβ”€β”€ thera_llava.py              # Lazy LLaVA loader
└── weights/                    # Download weights here; not tracked by git
    β”œβ”€β”€ model.pt                # TherA Model
    β”œβ”€β”€ merged_models/          # Initialization model
    β”‚   β”œβ”€β”€ unet/
    β”‚   └── adapter/
    β”œβ”€β”€ stable-diffusion/       
    β”‚   β”œβ”€β”€ vae/
    β”‚   └── scheduler/
    β”œβ”€β”€ reference_caches/
    β”‚   β”œβ”€β”€ SUNNY.pt
    β”‚   β”œβ”€β”€ CLOUDY.pt
    β”‚   β”œβ”€β”€ RAINY.pt
    β”‚   └── NIGHT.pt
    β”œβ”€β”€ reference_caches/
    β”‚   β”‚   β”œβ”€β”€ SUNNY.pt
    β”‚   β”‚   β”œβ”€β”€ CLOUDY.pt
    β”‚   β”‚   β”œβ”€β”€ RAINY.pt
    β”‚   β”‚   └── NIGHT.pt
    └── TherA-VLM/                  # Optional; only for on-the-fly mode
        β”œβ”€β”€ adaptor_config.json/
        └── adapter_model.safetensors
        └── config.json
        └── non_lora_trainables.bin
        └── trainer_state.json
```

---

## Installation

### Option 1: Local Python Environment

```bash
git clone https://github.com/donkeymouse/TherA.git
cd TherA

python -m venv .venv
source .venv/bin/activate

pip install --upgrade pip
pip install -r requirements.txt
```

**Recommended environment**

- Python 3.10+
- CUDA-capable GPU
- 16 GB+ VRAM recommended for comfortable inference

---

### Option 2: Docker

A prebuilt Docker image is available at:

```bash
docker pull donkeymouse/thera:latest
```

Example interactive run:

```bash
docker run --gpus all --rm -it \
  -v "$(pwd)":/workspace/TherA \
  -w /workspace/TherA \
  donkeymouse/thera:latest \
  bash
```

Then run inference commands from inside the container.

---

## Download Weights

TherA weights are hosted on Hugging Face:

```bash
pip install -U huggingface_hub

huggingface-cli download donkeymouse/TherA \
  --local-dir weights
```

After downloading, your `weights/` directory should contain:

| Path | Description | Required? |
|---|---|---|
| `weights/model.pt` | TherA trained UNet and adapter checkpoint | Yes |
| `weights/merged_models/unet/` | UNet architecture/config files | Yes |
| `weights/merged_models/adapter/` | TextAdapter architecture/config files | Yes |
| `weights/stable-diffusion/vae/` | Stable Diffusion VAE | Yes |
| `weights/stable-diffusion/scheduler/` | DDIM scheduler config | Yes |
| `weights/reference_caches/*.pt` | Precomputed LLaVA hidden states for inference palettes | Recommended |
| `weights/TherA-VLM/` | LLaVA weights for on-the-fly feature extraction | Optional |

---

## Optional: Download LLaVA Weights

LLaVA is only required for **on-the-fly feature extraction** or **two-image guided mode**. It is not required for reference-cache inference.

```bash
huggingface-cli download llava-hf/llava-1.5-7b-hf \
  --local-dir weights/llava-1.5-7b-hf
```


---

## Quick Start

---

## Full RGB-TIR translation using TherA-VLM

Use this mode if you want to extract hidden states from TherA directly at runtime from an RGB image and prompt.

```bash
python infer_custom.py \
  --rgb-dir examples/rgb \
  --output-dir preds \
  --llava-base-path weights/llava-1.5-7b-hf \
  --llava-lora-path weights/TherA-VLM \
  --llava-prompt "How would this RGB scene appear in long-wave thermal infrared spectrum."
```

This mode is more expensive because it loads LLaVA during inference.



### Reference-Guided Image Translation Mode

This mode extracts LLaVA features from a reference RGB image and applies them to a target RGB image.

```bash
python infer_example_guided.py \
  --mode two-image \
  --reference-image examples/ref/rgb.jpg \
  --input-image examples/rgb/scene.jpg \
  --output preds/scene_tir.png \
  --llava-base-path weights/llava-1.5-7b-hf \
  --llava-lora-path weights/TherA-VLM
```

---

### Recursive Folder Inference

```bash
python infer_custom.py \
  --rgb-dir /path/to/dataset/RGB \
  --output-dir preds \
  --reference-cache weights/reference_caches/SUNNY.pt \
  --recursive
```

When `--recursive` is used, the output folder preserves the input directory structure.

---
---

## Reference-cache Mode
Reference-cache mode is the recommended if you are lacking GPU memory. It does not load LLaVA at runtime.

```bash
python infer_custom.py \
  --rgb-dir examples/rgb \
  --output-dir preds/sunny \
  --reference-cache weights/reference_caches/SUNNY.pt
```

The script reads all images in `examples/rgb` and writes translated TIR images to `preds/sunny`.

A lighter version of the text-guided image translation module. 

Example palette caches:

```text
weights/reference_caches/SUNNY.pt
weights/reference_caches/CLOUDY.pt
weights/reference_caches/RAINY.pt
weights/reference_caches/NIGHT.pt
```

You can use different pallete cache to achieve different translation effects. 

---

## Inference Modes

| Mode | Main flag / script | LLaVA weights needed? | Recommended use |
|---|---|---:|---|
| Reference cache | `--reference-cache path.pt` | No | Default deployment and fast inference |
| Per-image cache directory | `--cache-dir dir/` | No | Precomputed feature per image |
| Full RGB-TIR translation| `--llava-base-path ...` | Yes | Runtime prompt/image conditioning |
| Reference image-guided translation| `infer_example_guided.py --mode two-image` | Yes | Apply reference-image conditioning |

---

## Reference Cache Format

Reference caches are precomputed LLaVA hidden states saved as `.pt` files.

Supported tensor shapes:

```text
[1, L, 4096]
[L, 4096]
```

A single reference cache can be applied to all input images as a global thermal/weather/style condition.

---

## Important Arguments

| Argument | Default | Description |
|---|---:|---|
| `--checkpoint` | `weights/checkpoint` | Directory containing `model.pt` |
| `--merged-model-path` | `weights/merged_models` | Directory containing UNet and adapter configs |
| `--pretrained-sd` | `weights/stable-diffusion` | Directory containing VAE and scheduler |
| `--rgb-dir` | Required | Folder of RGB images for batch inference |
| `--output-dir` | `custom_predictions` | Output folder for predictions |
| `--reference-cache` | `None` | Single `.pt` cache used for all images |
| `--cache-dir` | `None` | Folder of per-image `.pt` caches matched by filename stem |
| `--llava-base-path` | `None` | Base LLaVA model path for on-the-fly mode |
| `--llava-lora-path` | `None` | Optional LLaVA LoRA path |
| `--llava-prompt` | thermal prompt | Prompt used for default inference/text-guided translation|
| `--num-steps` | `100` | DDIM sampling steps |
| `--cfg-text` | `3.5` | Text/VLM guidance strength |
| `--cfg-image` | `1.5` | Image guidance strength |
| `--target-size` | Auto | Resize image to this square size; otherwise dimensions are rounded to multiples of 32 |
| `--recursive` | Off | Recursively process subdirectories |
| `--device` | `cuda` | Device for inference |

---

## Architecture

```text
RGB image
   β”‚
   β–Ό
VAE encoder ──► RGB latents ───────────────────┐
                                                β”‚
                                                β”œβ”€β”€β–Ί 8-channel diffusion UNet ──► VAE decoder ──► TIR image
                                                β”‚
LLaVA hidden state, 4096-d ──► TextAdapter β”€β”€β”€β”€β”€β”˜
                              768-d cross-attention tokens
```

TherA uses dual classifier-free guidance at inference by combining:

- full conditioning,
- image-only conditioning,
- text/VLM-only conditioning.

---

## R2T2 Dataset

TherA is trained with **R2T2**, a large-scale RGB–TIR–Text dataset.

R2T2 includes:

- **112,970 aligned triplets**: RGB image, TIR image, and canonical thermal schema.
- Scene diversity across driving, CCTV, aerial, and ego-view settings.
- Temporal diversity across day/night and diurnal transitions.
- Environmental diversity across weather, season, and illumination.
- Material- and object-level annotations with structured canonicalization.
- Data compiled from multiple aligned RGB–TIR datasets with additional pseudo-aligned pairs.

Dataset page:

```text
https://huggingface.co/datasets/donkeymouse/TherA-R2T2
```

Example structure:

```text
R2T2/
β”œβ”€β”€ ${DATASET_NAME}/
β”‚   └── ${SEQUENCE_NAME}/
β”‚       β”œβ”€β”€ RGB/
β”‚       β”‚   β”œβ”€β”€ 1.jpg
β”‚       β”‚   └── ...
β”‚       └── TIR/
β”‚           β”œβ”€β”€ 1.jpg
β”‚           └── ...
β”œβ”€β”€ ViVID/
β”‚   β”œβ”€β”€ img_campus_day1/
β”‚   β”‚   β”œβ”€β”€ RGB/
β”‚   β”‚   β”‚   β”œβ”€β”€ 000001.png
β”‚   β”‚   β”‚   └── ...
β”‚   β”‚   └── TIR/
β”‚   β”‚       β”œβ”€β”€ 000001.png
β”‚   β”‚       └── ...
β”‚   └── ...
└── ...
```

---

## Troubleshooting

### `Checkpoint not found: weights/model.pt`

Download the TherA weights and make sure `model.pt` is located at:

```text
weights/model.pt
```

---

### `OSError: ... stable-diffusion/vae`

Make sure the Stable Diffusion VAE and scheduler folders are present:

```text
weights/stable-diffusion/vae/
weights/stable-diffusion/scheduler/
```

---

### Outputs look identical across palettes

Try increasing text/VLM guidance:

```bash
--cfg-text 7.5
```

Also verify that your reference cache files are distinct:

```text
SUNNY.pt
CLOUDY.pt
RAINY.pt
NIGHT.pt
```

---

### CUDA out of memory

Try reducing the image size:

```bash
--target-size 512
```

You can also run one image at a time with:

```bash
python infer_example_guided.py
```

---

### LLaVA import or loading errors

Use reference-cache mode if you do not need runtime LLaVA extraction:

```bash
--reference-cache weights/reference_caches/SUNNY.pt
```

For on-the-fly mode, make sure the LLaVA base model and TherA weights are correctly loaded`.

---

## TODOs
- [x] inference code and R2T2 dataset
- [] Upload cache extraction code
- [] Improve text-guidance 


## Citation

If you find TherA useful for your research, please cite:

```bibtex
@inproceedings{lee2026thera,
  title     = {TherA: Thermal-Aware Visual-Language Prompting for Controllable RGB-to-Thermal Infrared Translation},
  author    = {Lee, Dong-Guw and Rhee, Tai Hyoung and Jang, Hyunsoo and Shin, Young-Sik and Shin, Ukcheol and Kim, Ayoung},
  booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year      = {2026}
}
```

You may also cite the arXiv version:

```bibtex
@article{lee2026thera_arxiv,
  title   = {TherA: Thermal-Aware Visual-Language Prompting for Controllable RGB-to-Thermal Infrared Translation},
  author  = {Lee, Dong-Guw and Rhee, Tai Hyoung and Jang, Hyunsoo and Shin, Young-Sik and Shin, Ukcheol and Kim, Ayoung},
  journal = {arXiv preprint arXiv:2602.19430},
  year    = {2026}
}
```

---

## Acknowledgements

TherA builds on open-source components from the vision-language and diffusion communities, including LLaVA, Stable Diffusion, Diffusers, and LaVi-Bridge-style adapter architectures.

---

## License

See `LICENSE` for details.

Third-party models, datasets, and libraries retain their own licenses. Please review the licenses for LLaVA, Stable Diffusion, Hugging Face model files, and any external datasets before use.

## Contact
If you have any questions, contact here please
```
donkeymouse@snu.ac.kr
```