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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"metadata": {
|
7 |
+
"colab": {
|
8 |
+
"base_uri": "https://localhost:8080/"
|
9 |
+
},
|
10 |
+
"id": "4mDGz9V6JC0a",
|
11 |
+
"outputId": "75309249-37c8-4ba6-e950-facc85a4c249"
|
12 |
+
},
|
13 |
+
"outputs": [
|
14 |
+
{
|
15 |
+
"output_type": "stream",
|
16 |
+
"name": "stdout",
|
17 |
+
"text": [
|
18 |
+
" Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n",
|
19 |
+
" Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n",
|
20 |
+
" Preparing metadata (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n",
|
21 |
+
" Building wheel for diffusers (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n"
|
22 |
+
]
|
23 |
+
}
|
24 |
+
],
|
25 |
+
"source": [
|
26 |
+
"!pip install git+https://github.com/cosmo3769/diffusers@standardize-model-card-t2i -q"
|
27 |
+
]
|
28 |
+
},
|
29 |
+
{
|
30 |
+
"cell_type": "code",
|
31 |
+
"source": [
|
32 |
+
"!pip install --upgrade wandb -q"
|
33 |
+
],
|
34 |
+
"metadata": {
|
35 |
+
"colab": {
|
36 |
+
"base_uri": "https://localhost:8080/"
|
37 |
+
},
|
38 |
+
"id": "hWoT-7tLrC3X",
|
39 |
+
"outputId": "25b205fa-5723-41c4-bf0f-e6c0604c2c19"
|
40 |
+
},
|
41 |
+
"execution_count": 2,
|
42 |
+
"outputs": [
|
43 |
+
{
|
44 |
+
"output_type": "stream",
|
45 |
+
"name": "stdout",
|
46 |
+
"text": [
|
47 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.2/2.2 MB\u001b[0m \u001b[31m10.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
48 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m196.4/196.4 kB\u001b[0m \u001b[31m27.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
49 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m257.8/257.8 kB\u001b[0m \u001b[31m33.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
50 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m62.7/62.7 kB\u001b[0m \u001b[31m9.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
51 |
+
"\u001b[?25h"
|
52 |
+
]
|
53 |
+
}
|
54 |
+
]
|
55 |
+
},
|
56 |
+
{
|
57 |
+
"cell_type": "code",
|
58 |
+
"source": [
|
59 |
+
"import os\n",
|
60 |
+
"import wandb\n",
|
61 |
+
"from argparse import Namespace\n",
|
62 |
+
"from diffusers.utils import is_wandb_available, make_image_grid\n",
|
63 |
+
"from diffusers.utils.hub_utils import load_or_create_model_card, populate_model_card"
|
64 |
+
],
|
65 |
+
"metadata": {
|
66 |
+
"id": "r0rK5JfUrAfc"
|
67 |
+
},
|
68 |
+
"execution_count": 3,
|
69 |
+
"outputs": []
|
70 |
+
},
|
71 |
+
{
|
72 |
+
"cell_type": "code",
|
73 |
+
"source": [
|
74 |
+
"def save_model_card(\n",
|
75 |
+
" args,\n",
|
76 |
+
" repo_id: str,\n",
|
77 |
+
" images=None,\n",
|
78 |
+
" repo_folder=None,\n",
|
79 |
+
"):\n",
|
80 |
+
" img_str = \"\"\n",
|
81 |
+
" if len(images) > 0:\n",
|
82 |
+
" image_grid = make_image_grid(images, 1, len(args.validation_prompts))\n",
|
83 |
+
" image_grid.save(os.path.join(repo_folder, \"val_imgs_grid.png\"))\n",
|
84 |
+
" img_str += \"![val_imgs_grid](./val_imgs_grid.png)\\n\"\n",
|
85 |
+
"\n",
|
86 |
+
" model_description = f\"\"\"\n",
|
87 |
+
"# Text-to-image finetuning - {repo_id}\n",
|
88 |
+
"\n",
|
89 |
+
"This pipeline was finetuned from **{args.pretrained_model_name_or_path}** on the **{args.dataset_name}** dataset. Below are some example images generated with the finetuned pipeline using the following prompts: {args.validation_prompts}: \\n\n",
|
90 |
+
"{img_str}\n",
|
91 |
+
"\n",
|
92 |
+
"## Pipeline usage\n",
|
93 |
+
"\n",
|
94 |
+
"You can use the pipeline like so:\n",
|
95 |
+
"\n",
|
96 |
+
"```python\n",
|
97 |
+
"from diffusers import DiffusionPipeline\n",
|
98 |
+
"import torch\n",
|
99 |
+
"\n",
|
100 |
+
"pipeline = DiffusionPipeline.from_pretrained(\"{repo_id}\", torch_dtype=torch.float16)\n",
|
101 |
+
"prompt = \"{args.validation_prompts[0]}\"\n",
|
102 |
+
"image = pipeline(prompt).images[0]\n",
|
103 |
+
"image.save(\"my_image.png\")\n",
|
104 |
+
"```\n",
|
105 |
+
"\n",
|
106 |
+
"## Training info\n",
|
107 |
+
"\n",
|
108 |
+
"These are the key hyperparameters used during training:\n",
|
109 |
+
"\n",
|
110 |
+
"* Epochs: {args.num_train_epochs}\n",
|
111 |
+
"* Learning rate: {args.learning_rate}\n",
|
112 |
+
"* Batch size: {args.train_batch_size}\n",
|
113 |
+
"* Gradient accumulation steps: {args.gradient_accumulation_steps}\n",
|
114 |
+
"* Image resolution: {args.resolution}\n",
|
115 |
+
"* Mixed-precision: {args.mixed_precision}\n",
|
116 |
+
"\n",
|
117 |
+
"\"\"\"\n",
|
118 |
+
" wandb_info = \"\"\n",
|
119 |
+
" if is_wandb_available():\n",
|
120 |
+
" wandb_run_url = None\n",
|
121 |
+
" if wandb.run is not None:\n",
|
122 |
+
" wandb_run_url = wandb.run.url\n",
|
123 |
+
"\n",
|
124 |
+
" if wandb_run_url is not None:\n",
|
125 |
+
" wandb_info = f\"\"\"\n",
|
126 |
+
"More information on all the CLI arguments and the environment are available on your [`wandb` run page]({wandb_run_url}).\n",
|
127 |
+
"\"\"\"\n",
|
128 |
+
"\n",
|
129 |
+
" model_description += wandb_info\n",
|
130 |
+
"\n",
|
131 |
+
" model_card = load_or_create_model_card(\n",
|
132 |
+
" repo_id_or_path=repo_id,\n",
|
133 |
+
" from_training=True,\n",
|
134 |
+
" license=\"creativeml-openrail-m\",\n",
|
135 |
+
" base_model=args.pretrained_model_name_or_path,\n",
|
136 |
+
" model_description=model_description,\n",
|
137 |
+
" inference=True,\n",
|
138 |
+
" )\n",
|
139 |
+
"\n",
|
140 |
+
" tags = [\"stable-diffusion\", \"stable-diffusion-diffusers\", \"text-to-image\", \"diffusers\"]\n",
|
141 |
+
" model_card = populate_model_card(model_card, tags=tags)\n",
|
142 |
+
"\n",
|
143 |
+
" model_card.save(os.path.join(repo_folder, \"README.md\"))"
|
144 |
+
],
|
145 |
+
"metadata": {
|
146 |
+
"id": "6mgnDhfzrTp4"
|
147 |
+
},
|
148 |
+
"execution_count": 4,
|
149 |
+
"outputs": []
|
150 |
+
},
|
151 |
+
{
|
152 |
+
"cell_type": "code",
|
153 |
+
"source": [
|
154 |
+
"args = Namespace(\n",
|
155 |
+
" pretrained_model_name_or_path=\"runwayml/stable-diffusion-v1-5\",\n",
|
156 |
+
" dataset_name=\"your_dataset_name\",\n",
|
157 |
+
" validation_prompts=[\"prompt1\", \"prompt2\", \"prompt3\"],\n",
|
158 |
+
" num_train_epochs=\"num_train_epochs\",\n",
|
159 |
+
" learning_rate=\"lr\",\n",
|
160 |
+
" train_batch_size=\"batch_size\",\n",
|
161 |
+
" gradient_accumulation_steps=\"ga_steps\",\n",
|
162 |
+
" resolution=\"img_resolution\",\n",
|
163 |
+
" mixed_precision=\"boolean\"\n",
|
164 |
+
")"
|
165 |
+
],
|
166 |
+
"metadata": {
|
167 |
+
"id": "UfgqlRHw0hQE"
|
168 |
+
},
|
169 |
+
"execution_count": 5,
|
170 |
+
"outputs": []
|
171 |
+
},
|
172 |
+
{
|
173 |
+
"cell_type": "code",
|
174 |
+
"source": [
|
175 |
+
"from diffusers.utils import load_image\n",
|
176 |
+
"\n",
|
177 |
+
"images = [\n",
|
178 |
+
" load_image(\"https://huggingface.co/datasets/diffusers/docs-images/resolve/main/amused/A%20mushroom%20in%20%5BV%5D%20style.png\")\n",
|
179 |
+
" for _ in range(3)\n",
|
180 |
+
"]\n",
|
181 |
+
"\n",
|
182 |
+
"save_model_card(\n",
|
183 |
+
" args,\n",
|
184 |
+
" repo_id=\"cosmo3769/test\",\n",
|
185 |
+
" images=images,\n",
|
186 |
+
" repo_folder=\".\",\n",
|
187 |
+
")"
|
188 |
+
],
|
189 |
+
"metadata": {
|
190 |
+
"id": "JTEDsOd_rm7-"
|
191 |
+
},
|
192 |
+
"execution_count": 6,
|
193 |
+
"outputs": []
|
194 |
+
},
|
195 |
+
{
|
196 |
+
"cell_type": "code",
|
197 |
+
"source": [
|
198 |
+
"!cat README.md"
|
199 |
+
],
|
200 |
+
"metadata": {
|
201 |
+
"colab": {
|
202 |
+
"base_uri": "https://localhost:8080/"
|
203 |
+
},
|
204 |
+
"id": "NwCOmASdsUCT",
|
205 |
+
"outputId": "37a56224-e66a-4b51-8233-b9b40958539a"
|
206 |
+
},
|
207 |
+
"execution_count": 7,
|
208 |
+
"outputs": [
|
209 |
+
{
|
210 |
+
"output_type": "stream",
|
211 |
+
"name": "stdout",
|
212 |
+
"text": [
|
213 |
+
"---\n",
|
214 |
+
"license: creativeml-openrail-m\n",
|
215 |
+
"library_name: diffusers\n",
|
216 |
+
"tags:\n",
|
217 |
+
"- stable-diffusion\n",
|
218 |
+
"- stable-diffusion-diffusers\n",
|
219 |
+
"- text-to-image\n",
|
220 |
+
"- diffusers\n",
|
221 |
+
"inference: true\n",
|
222 |
+
"base_model: runwayml/stable-diffusion-v1-5\n",
|
223 |
+
"---\n",
|
224 |
+
"\n",
|
225 |
+
"<!-- This model card has been generated automatically according to the information the training script had access to. You\n",
|
226 |
+
"should probably proofread and complete it, then remove this comment. -->\n",
|
227 |
+
"\n",
|
228 |
+
"\n",
|
229 |
+
"# Text-to-image finetuning - cosmo3769/test\n",
|
230 |
+
"\n",
|
231 |
+
"This pipeline was finetuned from **runwayml/stable-diffusion-v1-5** on the **your_dataset_name** dataset. Below are some example images generated with the finetuned pipeline using the following prompts: ['prompt1', 'prompt2', 'prompt3']: \n",
|
232 |
+
"\n",
|
233 |
+
"![val_imgs_grid](./val_imgs_grid.png)\n",
|
234 |
+
"\n",
|
235 |
+
"\n",
|
236 |
+
"## Pipeline usage\n",
|
237 |
+
"\n",
|
238 |
+
"You can use the pipeline like so:\n",
|
239 |
+
"\n",
|
240 |
+
"```python\n",
|
241 |
+
"from diffusers import DiffusionPipeline\n",
|
242 |
+
"import torch\n",
|
243 |
+
"\n",
|
244 |
+
"pipeline = DiffusionPipeline.from_pretrained(\"cosmo3769/test\", torch_dtype=torch.float16)\n",
|
245 |
+
"prompt = \"prompt1\"\n",
|
246 |
+
"image = pipeline(prompt).images[0]\n",
|
247 |
+
"image.save(\"my_image.png\")\n",
|
248 |
+
"```\n",
|
249 |
+
"\n",
|
250 |
+
"## Training info\n",
|
251 |
+
"\n",
|
252 |
+
"These are the key hyperparameters used during training:\n",
|
253 |
+
"\n",
|
254 |
+
"* Epochs: num_train_epochs\n",
|
255 |
+
"* Learning rate: lr\n",
|
256 |
+
"* Batch size: batch_size\n",
|
257 |
+
"* Gradient accumulation steps: ga_steps\n",
|
258 |
+
"* Image resolution: img_resolution\n",
|
259 |
+
"* Mixed-precision: boolean\n",
|
260 |
+
"\n",
|
261 |
+
"\n",
|
262 |
+
"\n",
|
263 |
+
"## Intended uses & limitations\n",
|
264 |
+
"\n",
|
265 |
+
"#### How to use\n",
|
266 |
+
"\n",
|
267 |
+
"```python\n",
|
268 |
+
"# TODO: add an example code snippet for running this diffusion pipeline\n",
|
269 |
+
"```\n",
|
270 |
+
"\n",
|
271 |
+
"#### Limitations and bias\n",
|
272 |
+
"\n",
|
273 |
+
"[TODO: provide examples of latent issues and potential remediations]\n",
|
274 |
+
"\n",
|
275 |
+
"## Training details\n",
|
276 |
+
"\n",
|
277 |
+
"[TODO: describe the data used to train the model]"
|
278 |
+
]
|
279 |
+
}
|
280 |
+
]
|
281 |
+
},
|
282 |
+
{
|
283 |
+
"cell_type": "code",
|
284 |
+
"source": [],
|
285 |
+
"metadata": {
|
286 |
+
"id": "w7IqDNR72RGf"
|
287 |
+
},
|
288 |
+
"execution_count": null,
|
289 |
+
"outputs": []
|
290 |
+
}
|
291 |
+
],
|
292 |
+
"metadata": {
|
293 |
+
"colab": {
|
294 |
+
"provenance": []
|
295 |
+
},
|
296 |
+
"kernelspec": {
|
297 |
+
"display_name": "Python 3",
|
298 |
+
"name": "python3"
|
299 |
+
},
|
300 |
+
"language_info": {
|
301 |
+
"name": "python"
|
302 |
+
}
|
303 |
+
},
|
304 |
+
"nbformat": 4,
|
305 |
+
"nbformat_minor": 0
|
306 |
+
}
|