SafeCFG: Controlling Harmful Features with Dynamic Safe Guidance for Safe Generation

Jiadong Pan, Liang Li, Hongcheng Gao, Zheng-Jun Zha, Qingming Huang +1 more
12/20/2024
cs.CV

No confident code implementation found for this paper.

Abstract

Diffusion models (DMs) have demonstrated exceptional performance in text-to-image tasks, leading to their widespread use. With the introduction of classifier-free guidance (CFG), the quality of images generated by DMs is significantly improved. However, one can use DMs to generate more harmful images by maliciously guiding the image generation process through CFG. Existing safe alignment methods aim to mitigate the risk of generating harmful images but often reduce the quality of clean image generation. To address this issue, we propose SafeCFG to adaptively control harmful features with dynamic safe guidance by modulating the CFG generation process. It dynamically guides the CFG generation process based on the harmfulness of the prompts, inducing significant deviations only in harmful CFG generations, achieving high quality and safety generation. SafeCFG can simultaneously modulate different harmful CFG generation processes, so it could eliminate harmful elements while preserving high-quality generation. Additionally, SafeCFG provides the ability to detect image harmfulness, allowing unsupervised safe alignment on DMs without pre-defined clean or harmful labels. Experimental results show that images generated by SafeCFG achieve both high quality and safety, and safe DMs trained in our unsupervised manner also exhibit good safety performance.

View on arXivView PDF

Code Implementations

No confident code match yet

We couldn't find an author-owned or strongly-evidenced community implementation for this paper. Any repos shown below are weak matches — verify before relying on them.

No code implementations found yet.

Know of an implementation? Let us know in the comments below!

Similar Papers

Cite this paper

@article{pan2024safecfg,
  title  = {SafeCFG: Controlling Harmful Features with Dynamic Safe Guidance for Safe Generation},
  author = {Jiadong Pan and Liang Li and Hongcheng Gao and Zheng-Jun Zha and Qingming Huang and Jiebo Luo},
  year   = {2024},
  eprint = {2412.16039},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2412.16039v2}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2412.16039.svg)](https://codeofpaper.com/paper/2412.16039)

Discussion