Bhavay-2001 commited on
Commit
fe0ad4e
1 Parent(s): f693038

Upload 3 files

Browse files
Files changed (3) hide show
  1. HF_Textual_Inversion.ipynb +253 -0
  2. README.md +41 -0
  3. image_control.png +0 -0
HF_Textual_Inversion.ipynb ADDED
@@ -0,0 +1,253 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "nbformat": 4,
3
+ "nbformat_minor": 0,
4
+ "metadata": {
5
+ "colab": {
6
+ "provenance": [],
7
+ "gpuType": "T4"
8
+ },
9
+ "kernelspec": {
10
+ "name": "python3",
11
+ "display_name": "Python 3"
12
+ },
13
+ "language_info": {
14
+ "name": "python"
15
+ },
16
+ "accelerator": "GPU"
17
+ },
18
+ "cells": [
19
+ {
20
+ "cell_type": "code",
21
+ "execution_count": 1,
22
+ "metadata": {
23
+ "colab": {
24
+ "base_uri": "https://localhost:8080/"
25
+ },
26
+ "id": "QV8xk7HmMX-M",
27
+ "outputId": "f92c1174-5e29-43fa-a54a-4dac3bfe6d59"
28
+ },
29
+ "outputs": [
30
+ {
31
+ "output_type": "stream",
32
+ "name": "stdout",
33
+ "text": [
34
+ "Cloning into 'diffusers'...\n",
35
+ "remote: Enumerating objects: 52829, done.\u001b[K\n",
36
+ "remote: Counting objects: 100% (1298/1298), done.\u001b[K\n",
37
+ "remote: Compressing objects: 100% (852/852), done.\u001b[K\n",
38
+ "remote: Total 52829 (delta 594), reused 966 (delta 418), pack-reused 51531\u001b[K\n",
39
+ "Receiving objects: 100% (52829/52829), 38.59 MiB | 24.11 MiB/s, done.\n",
40
+ "Resolving deltas: 100% (37517/37517), done.\n",
41
+ "/content/diffusers\n",
42
+ " Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n",
43
+ " Checking if build backend supports build_editable ... \u001b[?25l\u001b[?25hdone\n",
44
+ " Getting requirements to build editable ... \u001b[?25l\u001b[?25hdone\n",
45
+ " Preparing editable metadata (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n",
46
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m143.8/143.8 kB\u001b[0m \u001b[31m4.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
47
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m92.3/92.3 kB\u001b[0m \u001b[31m7.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
48
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m6.3/6.3 MB\u001b[0m \u001b[31m24.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
49
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m63.9/63.9 kB\u001b[0m \u001b[31m7.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
50
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m170.1/170.1 kB\u001b[0m \u001b[31m21.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
51
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m536.6/536.6 kB\u001b[0m \u001b[31m30.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
52
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.6/1.6 MB\u001b[0m \u001b[31m40.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
53
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m42.0/42.0 kB\u001b[0m \u001b[31m5.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
54
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m280.0/280.0 kB\u001b[0m \u001b[31m28.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
55
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m183.4/183.4 kB\u001b[0m \u001b[31m21.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
56
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m62.7/62.7 kB\u001b[0m \u001b[31m7.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
57
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m74.0/74.0 kB\u001b[0m \u001b[31m10.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
58
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.4/1.4 MB\u001b[0m \u001b[31m46.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
59
+ "\u001b[2K \u001b[90m���━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m44.6/44.6 kB\u001b[0m \u001b[31m5.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
60
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m756.0/756.0 kB\u001b[0m \u001b[31m46.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
61
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m61.2/61.2 kB\u001b[0m \u001b[31m6.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
62
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.2/2.2 MB\u001b[0m \u001b[31m44.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
63
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m38.3/38.3 MB\u001b[0m \u001b[31m14.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
64
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m116.3/116.3 kB\u001b[0m \u001b[31m15.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
65
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m134.8/134.8 kB\u001b[0m \u001b[31m17.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
66
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m53.4/53.4 kB\u001b[0m \u001b[31m6.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
67
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m202.9/202.9 kB\u001b[0m \u001b[31m26.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
68
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m54.5/54.5 kB\u001b[0m \u001b[31m7.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
69
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m257.9/257.9 kB\u001b[0m \u001b[31m30.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
70
+ "\u001b[?25h Building editable for diffusers (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n",
71
+ "\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n",
72
+ "ibis-framework 7.1.0 requires pyarrow<15,>=2, but you have pyarrow 15.0.0 which is incompatible.\u001b[0m\u001b[31m\n",
73
+ "\u001b[0m"
74
+ ]
75
+ }
76
+ ],
77
+ "source": [
78
+ "!git clone https://github.com/Bhavay-2001/diffusers\n",
79
+ "%cd diffusers\n",
80
+ "!pip install -q -e \".[dev]\""
81
+ ]
82
+ },
83
+ {
84
+ "cell_type": "code",
85
+ "source": [
86
+ "!pwd"
87
+ ],
88
+ "metadata": {
89
+ "colab": {
90
+ "base_uri": "https://localhost:8080/"
91
+ },
92
+ "id": "7tNQHp0MascO",
93
+ "outputId": "0ac02733-6a0f-484f-fd1b-ee58370e5bd8"
94
+ },
95
+ "execution_count": 2,
96
+ "outputs": [
97
+ {
98
+ "output_type": "stream",
99
+ "name": "stdout",
100
+ "text": [
101
+ "/content/diffusers\n"
102
+ ]
103
+ }
104
+ ]
105
+ },
106
+ {
107
+ "cell_type": "code",
108
+ "source": [
109
+ "import os\n",
110
+ "# /content/diffusers/src/diffusers/utils/hub_utils.py\n",
111
+ "from diffusers.src.diffusers.utils.hub_utils import load_or_create_model_card, populate_model_card"
112
+ ],
113
+ "metadata": {
114
+ "id": "kmQMzKuIXFvS"
115
+ },
116
+ "execution_count": 3,
117
+ "outputs": []
118
+ },
119
+ {
120
+ "cell_type": "code",
121
+ "source": [
122
+ "def save_model_card(repo_id: str, image_logs: dict =None, base_model: str=None, repo_folder: str=None):\n",
123
+ " img_str = \"\"\n",
124
+ " for i, log in enumerate(image_logs):\n",
125
+ " images = log[\"images\"]\n",
126
+ " validation_prompt = log[\"validation_prompt\"]\n",
127
+ " validation_image = log[\"validation_image\"]\n",
128
+ " validation_image.save(os.path.join(repo_folder, \"image_control.png\"))\n",
129
+ " img_str += f\"![img_{i}](./image_{i}.png)\\n\"\n",
130
+ "\n",
131
+ " model_description = f\"\"\"\n",
132
+ " # Textual inversion text2image fine-tuning - {repo_id}\n",
133
+ " These are textual inversion adaption weights for {base_model}. You can find some example images in the following. \\n\n",
134
+ " {img_str}\n",
135
+ " \"\"\"\n",
136
+ "\n",
137
+ " model_card = load_or_create_model_card(\n",
138
+ " repo_id_or_path=repo_id,\n",
139
+ " from_training=True,\n",
140
+ " license=\"creativeml-openrail-m\",\n",
141
+ " base_model=base_model,\n",
142
+ " model_description=model_description,\n",
143
+ " inference=True,\n",
144
+ " )\n",
145
+ "\n",
146
+ " tags = [\"stable-diffusion-xl\", \"stable-diffusion-xl-diffusers\", \"text-to-image\", \"diffusers\", \"textual_inversion\"]\n",
147
+ " model_card = populate_model_card(model_card, tags=tags)\n",
148
+ "\n",
149
+ " model_card.save(os.path.join(repo_folder, \"README.md\"))"
150
+ ],
151
+ "metadata": {
152
+ "id": "LiA0ILIdVp91"
153
+ },
154
+ "execution_count": 4,
155
+ "outputs": []
156
+ },
157
+ {
158
+ "cell_type": "code",
159
+ "source": [
160
+ "from diffusers.src.diffusers.utils import load_image\n",
161
+ "\n",
162
+ "images = [\n",
163
+ " load_image(\"https://huggingface.co/datasets/diffusers/docs-images/resolve/main/amused/A%20mushroom%20in%20%5BV%5D%20style.png\")\n",
164
+ " for _ in range(3)\n",
165
+ "]\n",
166
+ "\n",
167
+ "image_logs = [\n",
168
+ " dict(\n",
169
+ " images=[image],\n",
170
+ " validation_prompt=\"validation_prompt\",\n",
171
+ " validation_image=image,\n",
172
+ " )\n",
173
+ " for image in images\n",
174
+ "]\n",
175
+ "\n",
176
+ "save_model_card(\n",
177
+ " repo_id=\"Bhavay-2001/textual-inversion\",\n",
178
+ " image_logs=image_logs,\n",
179
+ " base_model=\"runwayml/stable-diffusion-v1-5\",\n",
180
+ " repo_folder=\".\",\n",
181
+ ")"
182
+ ],
183
+ "metadata": {
184
+ "id": "5UN8yQmYXEYQ"
185
+ },
186
+ "execution_count": 5,
187
+ "outputs": []
188
+ },
189
+ {
190
+ "cell_type": "code",
191
+ "source": [
192
+ "!cat README.md"
193
+ ],
194
+ "metadata": {
195
+ "colab": {
196
+ "base_uri": "https://localhost:8080/"
197
+ },
198
+ "id": "yzaVaH8qfacW",
199
+ "outputId": "fed30f61-1e39-4d5d-93cf-c31e92bb5950"
200
+ },
201
+ "execution_count": 6,
202
+ "outputs": [
203
+ {
204
+ "output_type": "stream",
205
+ "name": "stdout",
206
+ "text": [
207
+ "---\n",
208
+ "license: creativeml-openrail-m\n",
209
+ "library_name: diffusers\n",
210
+ "tags:\n",
211
+ "- stable-diffusion-xl\n",
212
+ "- stable-diffusion-xl-diffusers\n",
213
+ "- text-to-image\n",
214
+ "- diffusers\n",
215
+ "- textual_inversion\n",
216
+ "inference: true\n",
217
+ "base_model: runwayml/stable-diffusion-v1-5\n",
218
+ "---\n",
219
+ "\n",
220
+ "<!-- This model card has been generated automatically according to the information the training script had access to. You\n",
221
+ "should probably proofread and complete it, then remove this comment. -->\n",
222
+ "\n",
223
+ "\n",
224
+ " # Textual inversion text2image fine-tuning - Bhavay-2001/textual-inversion\n",
225
+ " These are textual inversion adaption weights for runwayml/stable-diffusion-v1-5. You can find some example images in the following. \n",
226
+ "\n",
227
+ " ![img_0](./image_0.png)\n",
228
+ "![img_1](./image_1.png)\n",
229
+ "![img_2](./image_2.png)\n",
230
+ "\n",
231
+ " \n",
232
+ "\n",
233
+ "## Intended uses & limitations\n",
234
+ "\n",
235
+ "#### How to use\n",
236
+ "\n",
237
+ "```python\n",
238
+ "# TODO: add an example code snippet for running this diffusion pipeline\n",
239
+ "```\n",
240
+ "\n",
241
+ "#### Limitations and bias\n",
242
+ "\n",
243
+ "[TODO: provide examples of latent issues and potential remediations]\n",
244
+ "\n",
245
+ "## Training details\n",
246
+ "\n",
247
+ "[TODO: describe the data used to train the model]"
248
+ ]
249
+ }
250
+ ]
251
+ }
252
+ ]
253
+ }
README.md ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: creativeml-openrail-m
3
+ library_name: diffusers
4
+ tags:
5
+ - stable-diffusion-xl
6
+ - stable-diffusion-xl-diffusers
7
+ - text-to-image
8
+ - diffusers
9
+ - textual_inversion
10
+ inference: true
11
+ base_model: runwayml/stable-diffusion-v1-5
12
+ ---
13
+
14
+ <!-- This model card has been generated automatically according to the information the training script had access to. You
15
+ should probably proofread and complete it, then remove this comment. -->
16
+
17
+
18
+ # Textual inversion text2image fine-tuning - Bhavay-2001/textual-inversion
19
+ These are textual inversion adaption weights for runwayml/stable-diffusion-v1-5. You can find some example images in the following.
20
+
21
+ ![img_0](./image_0.png)
22
+ ![img_1](./image_1.png)
23
+ ![img_2](./image_2.png)
24
+
25
+
26
+
27
+ ## Intended uses & limitations
28
+
29
+ #### How to use
30
+
31
+ ```python
32
+ # TODO: add an example code snippet for running this diffusion pipeline
33
+ ```
34
+
35
+ #### Limitations and bias
36
+
37
+ [TODO: provide examples of latent issues and potential remediations]
38
+
39
+ ## Training details
40
+
41
+ [TODO: describe the data used to train the model]
image_control.png ADDED