FlowGuard: Towards Lightweight In-Generation Safety Detection for Diffusion Models via Linear Latent Decoding
Organizations: Fudan University, Shanghai, China · Fudan University, Shanghai Innovation Institute, Shanghai, China
Abstract
Diffusion-based image generation models have advanced rapidly but pose a safety risk due to their potential to generate Not-Safe-For-Work (NSFW) content. Existing NSFW detection methods mainly operate either before or after image generation. Pre-generation methods rely on text prompts and struggle with the gap between prompt safety and image safety. Post-generation methods apply classifiers to final outputs, but they are poorly suited to intermediate noisy images. To address this, we introduce FlowGuard, a cross-model in-generation detection framework that inspects intermediate denoising steps. This is particularly challenging in latent diffusion, where early-stage noise obscures visual signals. FlowGuard employs a novel linear approximation for latent decoding and leverages a curriculum learning approach to stabilize training. By detecting unsafe content early, FlowGuard reduces unnecessary diffusion steps to cut computational costs. Our cross-model benchmark spanning nine diffusion-based backbones shows the effectiveness of FlowGuard for in-generation NSFW detection in both in-distribution and out-of-distribution settings, outperforming existing methods by over 30% in F1 score while delivering transformative efficiency gains, including slashing peak GPU memory demand by over 97% and projection time from 8.1 seconds to 0.2 seconds compared to standard VAE decoding.
Figures & tables
| ID | OOD | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| PixArt | Flux1 | Flux2 | SDv1.5 | SD3 | SDXL | Qwen-Image | Zimage | SD3.5 | ||
| Falconsai ( Xue et al., 2025 ) | Accuracy | 0.5010 | 0.5000 | 0.5501 | 0.4950 | 0.5013 | 0.4516 | 0.5005 | 0.5574 | 0.5760 |
| Precision | 0.5010 | 0.5000 | 0.5501 | 0.4950 | 0.5013 | 0.4516 | 0.5005 | 0.5574 | 0.5760 | |
| Recall | 1.0000 | 1.0000 | 1.0000 | 1.0000 | 1.0000 | 1.0000 | 1.0000 | 1.0000 | 1.0000 | |
| F1-Score | 0.6676 | 0.6667 | 0.7098 | 0.6623 | 0.6678 | 0.6222 | 0.6671 | 0.7158 | 0.7310 | |
| LlavaGuard-7B ( Helff et al., 2025 ) | Accuracy | 0.4484 | 0.5534 | 0.5501 | 0.5930 | 0.6165 | 0.4933 | 0.5683 | 0.5910 | 0.5647 |
Appendix figures & tables3 assets
Supplementary material from the paper’s appendix.
Appendix
| Flux1 | Flux2 | PixArt | Qwen-Image | SD3 | SD3.5 | SDv1.5 | SDXL | Zimage | ||
|---|---|---|---|---|---|---|---|---|---|---|
| train | safe | 2705 | 683 | 2726 | 0 | 1251 | 0 | 2663 | 0 | 0 |
| unsafe | 1954 | 2034 | 4246 | 0 | 1294 | 0 | 3538 | 0 | 0 | |
| test | safe | 200 | 233 | 200 | 200 | 200 | 512 | 200 | 300 | 200 |
| unsafe | 250 | 196 | 249 | 496 | 200 | 438 | 255 | 300 | 249 |