kevin1103 commited on
Commit
c25de6d
Β·
verified Β·
1 Parent(s): b902a0f

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +115 -0
README.md ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: diffusers
3
+ tags:
4
+ - stable-diffusion
5
+ - stable-diffusion-v1-4
6
+ - concept-erasure
7
+ - machine-unlearning
8
+ - artistic-style-erasure
9
+ - nudity-erasure
10
+ pipeline_tag: text-to-image
11
+ ---
12
+
13
+ # SAGE: Exploring the Boundaries of Unsafe Concept Domain with Semantic-Augment Erasing
14
+
15
+ [arXiv](https://arxiv.org/abs/2506.09363) | [Code](https://github.com/KevinLight831/SAGE)
16
+
17
+ ## Overview
18
+
19
+ This repository provides the released SAGE checkpoints for concept and artistic-style erasure in Stable Diffusion v1.4.
20
+
21
+ SAGE is a semantic-augmentation framework that updates the text encoder of a diffusion model to erase a target concept while retaining general image-generation ability. These checkpoints are intended for the original Stable Diffusion v1.4 pipeline.
22
+
23
+ ## Available checkpoints
24
+
25
+ The repository is organized by erased concept or artistic style.
26
+
27
+ ```text
28
+ SAGE/
29
+ β”œβ”€β”€ nudity/
30
+ β”‚ β”œβ”€β”€ TextEncoder-text_encoder_full-epoch_999.pt
31
+ β”œβ”€β”€ vangogh/
32
+ β”‚ β”œβ”€β”€ TextEncoder-text_encoder_layer0-epoch_999.pt
33
+ └── monet/
34
+ β”œβ”€β”€ TextEncoder-text_encoder_layer0-epoch_999.pt
35
+ ```
36
+
37
+ The exact filenames may differ between releases. Use the checkpoint filename present in each directory.
38
+
39
+ | Directory | Target | Updated component |
40
+ |---|---|---|
41
+ | `nudity/` | nudity-related concepts | full CLIP text encoder |
42
+ | `vangogh/` | Vincent van Gogh artistic style | CLIP text-encoder layer 0 |
43
+ | `monet/` | Claude Monet artistic style | CLIP text-encoder layer 0 |
44
+
45
+ These files contain PyTorch state dictionaries for the edited text encoder. They are not complete Diffusers pipelines and require the original Stable Diffusion v1.4 model.
46
+
47
+ ## Base model
48
+
49
+ Use the original [Stable Diffusion v1.4 model](https://huggingface.co/CompVis/stable-diffusion-v1-4). The checkpoint should be loaded into the `text_encoder` component of the matching pipeline. Do not load these files as complete pipelines with `StableDiffusionPipeline.from_pretrained`.
50
+
51
+ ## Loading a checkpoint
52
+
53
+ ```bash
54
+ pip install torch diffusers transformers accelerate
55
+ ```
56
+
57
+ ```python
58
+ import torch
59
+ from diffusers import StableDiffusionPipeline
60
+
61
+ base_model = "CompVis/stable-diffusion-v1-4"
62
+ checkpoint = "path/to/TextEncoder-text_encoder_full-epoch_999.pt"
63
+
64
+ pipe = StableDiffusionPipeline.from_pretrained(
65
+ base_model,
66
+ torch_dtype=torch.float16,
67
+ )
68
+ state_dict = torch.load(checkpoint, map_location="cpu")
69
+ pipe.text_encoder.load_state_dict(state_dict, strict=False)
70
+ pipe = pipe.to("cuda")
71
+
72
+ image = pipe(
73
+ "a photo of a nudity person",
74
+ num_inference_steps=50,
75
+ guidance_scale=7.5,
76
+ ).images[0]
77
+ image.save("sage_result.png")
78
+ ```
79
+
80
+ For the style checkpoints, replace `checkpoint` with the corresponding file under `vangogh/` or `monet/`.
81
+
82
+ ## Reproducing generation
83
+
84
+ The complete implementation and evaluation scripts are available in the accompanying SAGE code repository. The reference generator accepts prompt CSV files containing `case_number`, `prompt`, and `evaluation_seed`.
85
+
86
+ ```bash
87
+ python generate-scripts/generate_images.py \
88
+ --prompts_path data/prompts/eval/SD-v1-4_NudeClasses_75_filtered.csv \
89
+ --folder_suffix nudity \
90
+ --save_path outputs/nudity \
91
+ --target_ckpt path/to/nudity/TextEncoder-text_encoder_full-epoch_999.pt \
92
+ --checkpoint_component text_encoder \
93
+ --origin_or_target target
94
+ ```
95
+
96
+ ## Evaluation settings
97
+
98
+ The paper-scale nudity evaluation uses the I2P prompt set with 4,703 samples, NudeNet confidence threshold `0.6`, the paper subset of exposed-part labels, COCO-10k utility evaluation, and Q16 as an additional inappropriate-content classifier. Smaller files such as `nudity_quick.csv`, `nudity.csv`, and `coco_200.csv` are intended for environment checks and fast iteration.
99
+
100
+ The style experiments evaluate both target-style erasure and retention of other artists' styles for Vincent van Gogh and Claude Monet.
101
+
102
+
103
+ ## Citation
104
+
105
+ If you use SAGE, please cite the corresponding SAGE paper and the upstream Stable Diffusion and evaluation projects.
106
+
107
+ ```bibtex
108
+ @article{zhu2025sage,
109
+ title={SAGE: Exploring the Boundaries of Unsafe Concept Domain with Semantic-Augment Erasing},
110
+ author={Zhu, Hongguang and Wei, Yunchao and Wang, Mengyu and Jiao, Siyu and Fang, Yan and Huang, Jiannan and Zhao, Yao},
111
+ journal={arXiv preprint arXiv:2506.09363},
112
+ year={2025}
113
+ }
114
+ ```
115
+