Skip to content

JonasLoos/sd-representation-anomalies

Repository files navigation

Latent Diffusion U-Net Representations Contain Positional Embeddings and Anomalies

ICLR 2025 DeLTa Workshop | [Project Page] [OpenReview] [arXiv]

Diffusion models have demonstrated remarkable capabilities in synthesizing realistic images, spurring interest in using their representations for various downstream tasks. To better understand the robustness of these representations, we analyze popular Stable Diffusion models using representational similarity and norms. Our findings reveal three phenomena: (1) the presence of a learned positional embedding in intermediate representations, (2) high-similarity corner artifacts, and (3) anomalous high-norm artifacts. These findings underscore the need to further investigate the properties of diffusion model representations before considering them for downstream tasks that require robust features.

Project Structure

  • data/: Cached data generated by run_experiments.py
  • labeler/: Labling Tool
  • project_page/: Files for the project page
  • create_dataset.py: Script to create the ImageNet subset used in the experiments
  • run_experiments.py: Script to execute the experiments and generate the data files
  • plot.py: Script to create the final plots
  • requirements.txt: Dependencies

Usage

We provide the full code to reproduce the quantitative experiments and plots in the paper. We include intermediate data files so that labeling the data and running the experiments is optional. It's important to run all code in the same environment and potentially on the same hardware, as different noise seeds lead to different anomalies.

  • Install requirements: pip install -r requirements.txt
  • Create the ImageNet subset: python create_dataset.py
  • High-norm anomaly labeling (optional):
    • cd labeler
    • Follow generate_norm_images.ipynb to generate the norm images for labeling
    • Run python app.py to start the labeling tool
    • Label the data in the browser (left click for anomalies (click on upper left token of the 2x2 anomalies), right click for next image)
    • Follow annotations_to_np.ipynb to convert the annotations to a numpy file
  • Run experiments (optional):
    • All experiments with default models (sd15, sd21, sdturbo): python run_experiments.py
    • With specific models and experiments: python run_experiments.py --models sd15 --experiments anomalies
  • Plot results: python plot.py

Citation

@inproceedings{loos2025latent,
  title={Latent Diffusion U-Net Representations Contain Positional Embeddings and Anomalies},
  author={Jonas Loos and Lorenz Linhardt},
  booktitle={ICLR 2025 Workshop on Deep Generative Model in Machine Learning: Theory, Principle and Efficacy},
  year={2025},
  url={https://openreview.net/forum?id=BCFNrZcqEL}
}

More

Related projects:

About

Repository for ICLR 2025 DeLTa Workshop Paper "Latent Diffusion U-Net Representations Contain Positional Embeddings and Anomalies"

Resources

Stars

Watchers

Forks

Contributors