ujin-song commited on
Commit
2fe52f3
1 Parent(s): f1bf571

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +133 -1
README.md CHANGED
@@ -10,4 +10,136 @@ pinned: false
10
  license: apache-2.0
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  license: apache-2.0
11
  ---
12
 
13
+ # Orthogonal Adaptation
14
+
15
+ ## 🔧 Dependencies and Installation
16
+
17
+ - Python >= 3.9 (Recommend to use [Anaconda](https://www.anaconda.com/download/#linux) or [Miniconda](https://docs.conda.io/en/latest/miniconda.html))
18
+ - Diffusers==0.19.3
19
+ - XFormer (is recommend to save memory)
20
+
21
+ ## ⏬ Pretrained Model and Data Preparation
22
+
23
+ ### Pretrained Model Preparation
24
+
25
+ We adopt the [ChilloutMix](https://civitai.com/models/6424/chilloutmix) fine-tuned model for generating human subjects.
26
+
27
+ ```bash
28
+ git clone https://github.com/TencentARC/Mix-of-Show.git
29
+
30
+ cd experiments/pretrained_models
31
+
32
+ # Diffusers-version ChilloutMix
33
+ git-lfs clone https://huggingface.co/windwhinny/chilloutmix.git
34
+ ```
35
+ <!-- ### Data Preparation
36
+
37
+ Note: Data selection and tagging are important in single-concept tuning. We strongly recommend checking the data processing in [sd-scripts](https://github.com/kohya-ss/sd-scripts). **In our ED-LoRA, we do not require any regularization dataset.** The detailed dataset preparation steps can refer to [Dataset.md](docs/Dataset.md). Our preprocessed data used in this repo is available at [Google Drive](https://drive.google.com/file/d/1O5oev8861N_KmKtqefb45l3SiSblbo5O/view?usp=sharing). -->
38
+
39
+ ## 🕹️ Single-Client Concept Tuning
40
+ ### Step 0: Data selection and Tagging for a single concept
41
+ Data selection and tagging are crucial in single-concept tuning. We strongly recommend checking the data processing in [sd-scripts](https://github.com/kohya-ss/sd-scripts). **In our ED-LoRA, we do not require any regularization dataset.**
42
+
43
+ 1. **Collect Images**: Gather 5-10 images of the concept you want to customize and place them inside a single folder located at `/single-concept/data/yourconceptname/image`. Ensure the images are consistent but also varied in appearance to prevent overfitting.
44
+
45
+ 2. **Create Captions**: Write captions for each image you collected. Save these captions as text files in the `/single-concept/data/yourconceptname/caption` directory.
46
+
47
+ 3. **Generate Masks**: To further improve the understanding of the concept, save masks of each image in the `/single-concept/data/yourconceptname/mask` directory. Use the `data_processing.ipynb` notebook for this step.
48
+
49
+ 4. **Create Data Configs**: In the `/single-concept/data_configs` directory, create a JSON file that summarizes the files you just created. The file name could be `yourconceptname.json`.
50
+
51
+
52
+ ### Step 1: Modify the Config at `/single-concept/train_configs`
53
+
54
+ Before tuning, it is essential to specify the data paths and adjust certain hyperparameters in the corresponding config file. Below are some basic config settings to be modified:
55
+
56
+ - **Concept List**: The data config that you just created should be referenced from 'concept_list'.
57
+ - **Validation Prompt**: You might want to set a proper validation prompt in `single-concept/validation_prompts` to visualize the single-concept sampling.
58
+
59
+
60
+ ```yaml
61
+ manual_seed: 1234 # this seed determines choice of columns from orthogonal basis (set differently for each concept)
62
+
63
+ datasets:
64
+ train:
65
+ # Concept data config
66
+ concept_list: single-concept/data_configs/hina_amano.json
67
+ replace_mapping:
68
+ <TOK>: <hina1> <hina2> # concept new token
69
+ val_vis:
70
+ # Validation prompt for visualization during tuning
71
+ prompts: single-concept/validation_prompts/characters/test_girl.txt
72
+ replace_mapping:
73
+ <TOK>: <hina1> <hina2> # Concept new token
74
+
75
+ models:
76
+ enable_edlora: true # true means ED-LoRA, false means vallina LoRA
77
+ new_concept_token: <hina1>+<hina2> # Concept new token, use "+" to connect
78
+ initializer_token: <rand-0.013>+girl
79
+ # Init token, only need to revise the later one based on the semantic category of given concept
80
+
81
+ val:
82
+ val_during_save: true # When saving checkpoint, visualize sample results.
83
+ compose_visualize: true # Compose all samples into a large grid figure for visualization
84
+ ```
85
+
86
+ ### Step 2: Start Tuning
87
+
88
+ We tune each concept with 2 A100 GPU. Similar to LoRA, community user can enable gradient accumulation, xformer, gradient checkpoint for tuning on one GPU.
89
+
90
+ ```bash
91
+ accelerate launch train_edlora.py -opt single-concept/0005_lebron_ortho.yml
92
+ ```
93
+ The LoRA weights for the single concept are saved inside the `/experiments/single-concept` folder under your concept name folder
94
+
95
+ ### Step 3: Single-concept Sampling
96
+ To sample an image from your trained weights from the last step, specify the model path in the sample config (located in `/single-concept/sample_configs`) and run the following command:
97
+
98
+ ```bash
99
+ python test_edlora.py -opt single-concept/sample_configs/8101_EDLoRA_potter_Cmix_B4_Repeat500.yml
100
+ ```
101
+
102
+ ## 🕹️ Merging LoRAs
103
+
104
+ ### Step 1: Collect Concept Models
105
+
106
+ Collect all concept models you want to extend the pretrained model and modify the config in `/multi-concept/merge_configs` accordingly.
107
+
108
+ ```yaml
109
+ [
110
+ {
111
+ "lora_path": "experiments/0022_elsa_ortho/models/edlora_model-latest.pth",
112
+ "unet_alpha": 1.8,
113
+ "text_encoder_alpha": 1.8,
114
+ "concept_name": "<elsa1> <elsa2>"
115
+ },
116
+ {
117
+ "lora_path": "experiments/0023_moana_ortho/models/edlora_model-latest.pth",
118
+ "unet_alpha": 1.8,
119
+ "text_encoder_alpha": 1.8,
120
+ "concept_name": "<moana1> <moana2>"
121
+ }
122
+ ... # keep adding new concepts for extending the pretrained models
123
+ ]
124
+ ```
125
+
126
+ ### Step 2: Weight Fusion
127
+ Specify which merge config you are using inside the `fuse.sh` file, and then run:
128
+
129
+ ```bash
130
+ bash fuse.sh
131
+ ```
132
+ The merged weights are now saved in the `/experiments/multi-concept` directory. This process is almost instant.
133
+
134
+ ### Step 3: Sample
135
+
136
+ **Regionally controllable multi-concept sampling:**
137
+
138
+ We utilize regionally controllable sampling from Mix-of-Show to enable multi-concept generation. Adding openpose conditioning greatly increases the reliability of generations.
139
+
140
+ Define which fused model inside `/experiments/multi-concept` you are going to use, and specify the keypose condition in `/multi-concept/pose_data` if needed. Also, modify the context prompts and regional prompts. Then run:
141
+
142
+ ```bash
143
+ bash regionally_sample.sh
144
+ ```
145
+ The samples from the multi-concept generation will now be stored in the `/results` folder.