File size: 10,138 Bytes
c881b77 | 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 | # Envisioning Beyond the Few: Disentangled Semantics and Primitives for Few-Shot Atypical Layout-to-Image Generation
**ICML 2026**
**Authors:** Nan Bao, Yifan Zhao, Wenzhuang Wang, Jia Li

## Environment Setup
We use two separate environments:
1. **Main environment** for core training and inference.
```bash
conda create -n dsp python=3.10.20
conda activate dsp
pip install torch==2.6.0 torchvision==0.21.0 torchaudio==2.6.0 --index-url https://download.pytorch.org/whl/cu126
pip install datasets==4.8.5 pillow==12.2.0 accelerate==1.13.0 transformers==5.8.1 diffusers==0.38.0 safetensors==0.8.0rc0 tensorboard==2.20.0 opencv-python==4.13.0.92 einops==0.8.2 imagesize==2.0.0 peft==0.19.1 ttach==0.0.3 ftfy==6.3.1 albumentations==2.0.8
```
2. **Evaluation environment** for MMDetection/MMEngine compatibility. It is used for evaluation with MMDetection/MMEngine due to strict version constraints, and also supports YOLO-based evaluation.
```bash
conda create -n dsp-eval python=3.10.20
conda activate dsp-eval
conda install mkl==2023.1.0 numpy==1.26.4
conda install pytorch==2.1.2 torchvision==0.16.2 torchaudio==2.1.2 pytorch-cuda=12.1 -c pytorch -c nvidia
pip install mmengine==0.10.7 tqdm==4.67.3 shapely==2.1.2 scipy==1.15.3 terminaltables==3.1.10 ultralytics==8.4.50 pycocotools==2.0.11 https://download.openmmlab.com/mmcv/dist/cu121/torch2.1.0/mmcv-2.1.0-cp310-cp310-manylinux1_x86_64.whl "numpy<2.0.0" "setuptools<70.0.0"
```
## Set Environment Variables
Set the root path of this project:
```bash
export DSP_PROJECT_DIR=/path/to/DSP # replace with the actual path
```
It is recommended to add this line to `~/.bashrc` or `~/.zshrc` for persistence.
## Pretrained Models Preparation
1. We use several pretrained models as external dependencies. Please download them manually from the following sources:
- [stable-diffusion-v1-5](https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-v1-5)
- [clip-vit-large-patch14](https://huggingface.co/openai/clip-vit-large-patch14)
- [dinov2_vitl14_pretrain.pth](https://dl.fbaipublicfiles.com/dinov2/dinov2_vitl14/dinov2_vitl14_pretrain.pth)
- [ViT-B-16.pt](https://openaipublic.azureedge.net/clip/models/5806e77cd80f8b59890b7e101eabd078d9fb84e6937f9e85e4ecb61988df416f/ViT-B-16.pt)
2. After downloading, organize the pretrained weights under `./pretrained` as follows:
```bash
pretrained
βββ stable-diffusion-v1-5
β βββ ...
βββ clip-vit-large-patch14
β βββ ...
βββ dinov2_vitl14_pretrain.pth
βββ ViT-B-16.pt
```
You may either copy or symlink the files. We recommend using symbolic links:
```bash
ln -s /path/to/stable-diffusion-v1-5 ./pretrained/stable-diffusion-v1-5
ln -s /path/to/clip-vit-large-patch14 ./pretrained/clip-vit-large-patch14
ln -s /path/to/dinov2_vitl14_pretrain.pth ./pretrained/dinov2_vitl14_pretrain.pth
ln -s /path/to/ViT-B-16.pt ./pretrained/ViT-B-16.pt
```
## Data Preparation
1. We use several public datasets. Please download them manually from the following sources:
- [DIOR](https://gcheng-nwpu.github.io/#Datasets)
- [RUOD](https://github.com/xiaoDetection/RUOD)
- [ExDark](https://github.com/cs-chan/Exclusively-Dark-Image-Dataset/tree/master/Dataset)
2. Unzip the downloaded datasets and organize the external dataset directories as follows:
```bash
DIOR-VOC
βββ Annotations
β βββ Horizontal_Bounding_Boxes
β βββ Oriented_Bounding_Boxes
βββ VOC2007
βββ ImageSets
β βββ Layout
β βββ Main
β βββ Segmentation
βββ JPEGImages
```
```bash
RUOD
βββ Environment_pic
β βββ blur
β βββ color
β βββ light
βββ Environmet_ANN
βββ RUOD_ANN
βββ RUOD_pic
βββ test
βββ train
```
```bash
ExDark
βββ annos
βββ imageclasslist.txt
βββ images
```
3. Run data preprocessing scripts located in `./scripts/data_process`, after updating all hard-coded paths (e.g., `/path/to/DIOR_VOC`, `/path/to/RUOD`, `/path/to/ExDark`) in the scripts to match the local setup. Execute them in order.
The preprocessing outputs will be generated under `./data` with the following structure:
```bash
data
βββ DIOR
β βββ dior_emb.pt
β βββ images -> /path/to/DIOR-VOC/VOC2007/JPEGImages
β βββ metadatas
β βββ patches
βββ EXDARK
β βββ exdark_emb.pt
β βββ images
β βββ metadatas
β βββ patches
βββ RUOD
βββ images -> /path/to/RUOD/RUOD_pic
βββ metadatas
βββ patches
βββ ruod_emb.pt
```
## Training and Inference
We provide three example configurations in `./configs`: `dsp-dior.yaml`, `dsp-ruod.yaml`, and `dsp-exdark.yaml`.
> **Argument Description:**
> - **config:** configuration file for model and dataset setup.
> - **metaseed:** seed generator identifier for deterministic sampling.
> - **num_seed:** number of sampling seeds for few-shot evaluation.
> - **k_shot:** number of samples per category in few-shot setting.
> - **run_id:** identifier for different runs.
> - **gpu_ids:** GPU device indices for execution.
> - **iter:** number of bootstrap iterations for FID.
### Base Phase Training
```bash
bash train_base.sh --config "dsp-dior"
bash train_base.sh --config "dsp-ruod"
bash train_base.sh --config "dsp-exdark"
```
### Novel Phase Training
```bash
bash train_novel.sh --config "dsp-dior" --metaseed "aaa" --num_seed 50 --k_shot "5" --run_id "1" --gpu_ids "0,1,2,3"
bash train_novel.sh --config "dsp-ruod" --metaseed "aaa" --num_seed 50 --k_shot "5" --run_id "1" --gpu_ids "0,1,2,3"
bash train_novel.sh --config "dsp-exdark" --metaseed "aaa" --num_seed 50 --k_shot "5" --run_id "1" --gpu_ids "0,1,2,3"
```
### Inference
```bash
bash infer.sh --config "dsp-dior" --metaseed "aaa" --num_seed 50 --k_shot "5" --run_id "1" --ckpt "100" --gpu_ids "0,1,2,3" --max_infer_size 50
bash infer.sh --config "dsp-ruod" --metaseed "aaa" --num_seed 50 --k_shot "5" --run_id "1" --ckpt "100" --gpu_ids "0,1,2,3" --max_infer_size 50
bash infer.sh --config "dsp-exdark" --metaseed "aaa" --num_seed 50 --k_shot "5" --run_id "1" --ckpt "100" --gpu_ids "0,1,2,3" --max_infer_size 50
```
## Evaluation
### Preparation
Download the YOLO and Faster R-CNN weights from [this link](https://drive.google.com/drive/folders/1FWN02KEuGPdEkXv38MmT8-D4-uQcAn4_?usp=sharing). Place them under `./pretrained`. The expected directory structure is as follows:
```bash
pretrained
βββ evaluation
β βββ mmdet
β β βββ faster_rcnn_r50_fpn_1x-dior
β β β βββ epoch_12.pth
β β βββ faster_rcnn_r50_fpn_1x-exdark
β β β βββ epoch_12.pth
β β βββ faster_rcnn_r50_fpn_1x-ruod
β β βββ epoch_12.pth
β βββ yolo
β βββ best.pt
βββ ... (pretrained models for training)
```
### YOLO (mAP / AP50 / AP75)
> **Note:** In yolo-wrapper-dior.sh, the `--xml_folder` path should be set to the DIOR annotation directory (`/path/to/DIOR-VOC/Annotations/Horizontal_Bounding_Boxes`).
```bash
cd $DSP_PROJECT_DIR/scripts/evaluation/yoloscore-dior
bash yolo-wrapper-dior.sh --config "dsp-dior" --metaseed "aaa" --num_seed 50 --ckpt "100" --k_shot "5" --run_id "1" --gpu_ids 0
```
### Faster R-CNN (mAP / AP50 / AP75)
```bash
cd $DSP_PROJECT_DIR/scripts/evaluation/FasterRCNN_score-mmdet
bash test-wrapper-dior.sh --config "dsp-dior" --metaseed "aaa" --num_seed 50 --ckpt "100" --k_shot "5" --run_id "1" --gpu_ids 0
bash test-wrapper-ruod.sh --config "dsp-ruod" --metaseed "aaa" --num_seed 50 --ckpt "100" --k_shot "5" --run_id "1" --gpu_ids 0
bash test-wrapper-exdark.sh --config "dsp-exdark" --metaseed "aaa" --num_seed 50 --ckpt "100" --k_shot "5" --run_id "1" --gpu_ids 0
```
### Bootstrap FID
```bash
cd $DSP_PROJECT_DIR/scripts/evaluation/bootstrap_fid
python boot_fid-dior.py --config dsp-dior -run_id 1 -num_seeds 50 --iter 50 --k_shot 5
python boot_fid-ruod.py --config dsp-ruod -run_id 1 -num_seeds 50 --iter 50 --k_shot 5
python boot_fid-exdark.py --config dsp-exdark -run_id 1 -num_seeds 50 --iter 50 --k_shot 5
```
Bootstrap FID results will be saved under `./metrics/BootstrapFID`.
### Detection Metric Summarization
```bash
cd $DSP_PROJECT_DIR/scripts/evaluation/summarize
bash summarize-wrapper.sh --config "dsp-dior" --k_shot "5" --run_id "1" --ckpt "100" --metaseed "aaa" --num_seed 50
bash summarize-wrapper.sh --config "dsp-ruod" --k_shot "5" --run_id "1" --ckpt "100" --metaseed "aaa" --num_seed 50
bash summarize-wrapper.sh --config "dsp-exdark" --k_shot "5" --run_id "1" --ckpt "100" --metaseed "aaa" --num_seed 50
```
Detection evaluation results (mAP / AP50 / AP75, YOLO and Faster R-CNN) will be summarized in `./metrics`.
## Acknowledgement
Our work is based on [stable diffusion](https://github.com/compvis/stable-diffusion), [diffusers](https://github.com/huggingface/diffusers), [CLIP](https://github.com/openai/CLIP), [DINOv2](https://github.com/facebookresearch/dinov2), [CC-Diff](https://github.com/AZZMM/CC-Diff), [MIGC](https://github.com/limuloo/MIGC), [GradCAM](https://github.com/linyq2117/CLIP-ES), and [kmeans_pytorch](https://github.com/subhadarship/kmeans_pytorch). Thanks for these great projects!
## Citation
If you find our work useful for your research, please cite the following paper.
```bib
@inproceedings{
bao2026envisioning,
title={Envisioning Beyond the Few: Disentangled Semantics and Primitives for Few-Shot Atypical Layout-to-Image Generation},
author={Bao, Nan and Zhao, Yifan and Wang, Wenzhuang and Li, Jia},
booktitle={Forty-third International Conference on Machine Learning},
year={2026},
url={https://openreview.net/forum?id=Jva4wVEySO}
}
``` |