Delete dreambooth_simple_joepenna.ipynb
Browse files- dreambooth_simple_joepenna.ipynb +0 -273
dreambooth_simple_joepenna.ipynb
DELETED
@@ -1,273 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"cells": [
|
3 |
-
{
|
4 |
-
"cell_type": "markdown",
|
5 |
-
"metadata": {},
|
6 |
-
"source": [
|
7 |
-
"# Dreambooth\n",
|
8 |
-
"Notebook implementation by David Bielejeski\n",
|
9 |
-
"Latest information on: https://github.com/JoePenna/Dreambooth-Stable-Diffusion"
|
10 |
-
]
|
11 |
-
},
|
12 |
-
{
|
13 |
-
"cell_type": "markdown",
|
14 |
-
"metadata": {},
|
15 |
-
"source": [
|
16 |
-
"## Build Environment"
|
17 |
-
]
|
18 |
-
},
|
19 |
-
{
|
20 |
-
"cell_type": "code",
|
21 |
-
"execution_count": null,
|
22 |
-
"metadata": {
|
23 |
-
"pycharm": {
|
24 |
-
"is_executing": true
|
25 |
-
}
|
26 |
-
},
|
27 |
-
"outputs": [],
|
28 |
-
"source": [
|
29 |
-
"from IPython.display import clear_output\n",
|
30 |
-
"from IPython.utils import io\n",
|
31 |
-
"\n",
|
32 |
-
"print(\"Installing widgets library...\")\n",
|
33 |
-
"with io.capture_output() as captured:\n",
|
34 |
-
" !pip install ipywidgets\n",
|
35 |
-
"clear_output()\n",
|
36 |
-
"\n",
|
37 |
-
"from JupyterNotebookHelpers.installer_progress_bar_widget import InstallerProgressBar\n",
|
38 |
-
"\n",
|
39 |
-
"show_detailed_output = False\n",
|
40 |
-
"install_commands = [\n",
|
41 |
-
" \"pip install omegaconf\",\n",
|
42 |
-
" \"pip install einops\",\n",
|
43 |
-
" \"pip install pytorch-lightning==1.6.5\",\n",
|
44 |
-
" \"pip install test-tube\",\n",
|
45 |
-
" \"pip install transformers\",\n",
|
46 |
-
" \"pip install kornia\",\n",
|
47 |
-
" \"pip install -e git+https://github.com/CompVis/taming-transformers.git@master#egg=taming-transformers\",\n",
|
48 |
-
" \"pip install -e git+https://github.com/openai/CLIP.git@main#egg=clip\",\n",
|
49 |
-
" \"pip install setuptools==59.5.0\",\n",
|
50 |
-
" \"pip install pillow==9.0.1\",\n",
|
51 |
-
" \"pip install torchmetrics==0.6.0\",\n",
|
52 |
-
" \"pip install -e .\",\n",
|
53 |
-
" \"pip install protobuf==3.20.1\",\n",
|
54 |
-
" \"pip install gdown\",\n",
|
55 |
-
" \"pip install -qq diffusers['training']==0.3.0 transformers ftfy\",\n",
|
56 |
-
" \"pip install huggingface_hub\",\n",
|
57 |
-
" \"pip install captionizer==1.0.1\",\n",
|
58 |
-
" \"pip install gitpython\",\n",
|
59 |
-
"]\n",
|
60 |
-
"\n",
|
61 |
-
"progress_bar = InstallerProgressBar()\n",
|
62 |
-
"progress_bar.show(install_commands)\n",
|
63 |
-
"\n",
|
64 |
-
"try:\n",
|
65 |
-
" for i, install_command in enumerate(install_commands):\n",
|
66 |
-
" if show_detailed_output:\n",
|
67 |
-
" !{install_command}\n",
|
68 |
-
" else:\n",
|
69 |
-
" with io.capture_output() as captured:\n",
|
70 |
-
" !{install_command}\n",
|
71 |
-
" print(f\"☑ '{install_command.replace('pip install ', '')}' installation complete.\")\n",
|
72 |
-
"\n",
|
73 |
-
" # update the progress bar\n",
|
74 |
-
" progress_bar.increment(i)\n",
|
75 |
-
"\n",
|
76 |
-
" progress_bar.close()\n",
|
77 |
-
" print(\"✅ All Dependencies successfully installed. Proceed to model download.\")\n",
|
78 |
-
"\n",
|
79 |
-
"except:\n",
|
80 |
-
" progress_bar.close()\n",
|
81 |
-
" print(\"❌ Error installing dependencies\")"
|
82 |
-
]
|
83 |
-
},
|
84 |
-
{
|
85 |
-
"cell_type": "markdown",
|
86 |
-
"metadata": {},
|
87 |
-
"source": [
|
88 |
-
"# Download a 1.* model"
|
89 |
-
]
|
90 |
-
},
|
91 |
-
{
|
92 |
-
"cell_type": "code",
|
93 |
-
"execution_count": null,
|
94 |
-
"metadata": {
|
95 |
-
"pycharm": {
|
96 |
-
"is_executing": true
|
97 |
-
}
|
98 |
-
},
|
99 |
-
"outputs": [],
|
100 |
-
"source": [
|
101 |
-
"from JupyterNotebookHelpers.download_model import DownloadModel\n",
|
102 |
-
"\n",
|
103 |
-
"download_model = DownloadModel()\n",
|
104 |
-
"download_model.show_form()"
|
105 |
-
]
|
106 |
-
},
|
107 |
-
{
|
108 |
-
"cell_type": "markdown",
|
109 |
-
"metadata": {},
|
110 |
-
"source": [
|
111 |
-
"## Dreambooth Training Environment Setup"
|
112 |
-
]
|
113 |
-
},
|
114 |
-
{
|
115 |
-
"cell_type": "code",
|
116 |
-
"execution_count": null,
|
117 |
-
"metadata": {
|
118 |
-
"pycharm": {
|
119 |
-
"is_executing": true
|
120 |
-
}
|
121 |
-
},
|
122 |
-
"outputs": [],
|
123 |
-
"source": [
|
124 |
-
"from JupyterNotebookHelpers.setup_training import SetupTraining\n",
|
125 |
-
"\n",
|
126 |
-
"setup_training = SetupTraining()\n",
|
127 |
-
"\n",
|
128 |
-
"# Pass our selected model to the training form\n",
|
129 |
-
"model_to_train_on = download_model.get_selected_model()\n",
|
130 |
-
"\n",
|
131 |
-
"# Show the form.\n",
|
132 |
-
"setup_training.show_form(\n",
|
133 |
-
" selected_model = model_to_train_on\n",
|
134 |
-
")"
|
135 |
-
]
|
136 |
-
},
|
137 |
-
{
|
138 |
-
"cell_type": "markdown",
|
139 |
-
"metadata": {},
|
140 |
-
"source": [
|
141 |
-
"## Training\n",
|
142 |
-
"\n",
|
143 |
-
"If training a person or subject, keep an eye on your project's `logs/{folder}/images/train/samples_scaled_gs-00xxxx` generations.\n",
|
144 |
-
"\n",
|
145 |
-
"If training a style, keep an eye on your project's `logs/{folder}/images/train/samples_gs-00xxxx` generations."
|
146 |
-
]
|
147 |
-
},
|
148 |
-
{
|
149 |
-
"cell_type": "code",
|
150 |
-
"execution_count": null,
|
151 |
-
"metadata": {
|
152 |
-
"pycharm": {
|
153 |
-
"is_executing": true
|
154 |
-
}
|
155 |
-
},
|
156 |
-
"outputs": [],
|
157 |
-
"source": [
|
158 |
-
"from JupyterNotebookHelpers.joe_penna_dreambooth_config import parse_config_file, JoePennaDreamboothConfigSchemaV1\n",
|
159 |
-
"from IPython.display import clear_output\n",
|
160 |
-
"import os\n",
|
161 |
-
"import shutil\n",
|
162 |
-
"\n",
|
163 |
-
"clear_output()\n",
|
164 |
-
"\n",
|
165 |
-
"# Load the config generated on the previous step\n",
|
166 |
-
"active_config_path = \"./joepenna-dreambooth-configs/active-config.json\"\n",
|
167 |
-
"config: JoePennaDreamboothConfigSchemaV1 = parse_config_file(active_config_path)\n",
|
168 |
-
"\n",
|
169 |
-
"if config is not None:\n",
|
170 |
-
" # Show the loaded config.\n",
|
171 |
-
" print(\"✅ Loaded the config file, proceeding to training\")\n",
|
172 |
-
" print(\"active-config.json\")\n",
|
173 |
-
" print(\"------------------\")\n",
|
174 |
-
" print(config.toJSON())\n",
|
175 |
-
"\n",
|
176 |
-
" reg_data_root = f\"/workspace/Dreambooth-Stable-Diffusion/regularization_images/{config.dataset}\"\n",
|
177 |
-
"\n",
|
178 |
-
" # Cleanup garbage files if they exist\n",
|
179 |
-
" leftover_training_files = [\"./training_images/.ipynb_checkpoints\", \"./regularization_images/.ipynb_checkpoints\"]\n",
|
180 |
-
" for i, ipynb_checkpoint_folder in enumerate(leftover_training_files):\n",
|
181 |
-
" if os.path.exists(ipynb_checkpoint_folder):\n",
|
182 |
-
" shutil.rmtree(ipynb_checkpoint_folder)\n",
|
183 |
-
"\n",
|
184 |
-
" # Train\n",
|
185 |
-
" !python \"main.py\" \\\n",
|
186 |
-
" --base \"configs/stable-diffusion/v1-finetune_unfrozen.yaml\" \\\n",
|
187 |
-
" -t \\\n",
|
188 |
-
" --actual_resume \"{config.model_filename}\" \\\n",
|
189 |
-
" --reg_data_root \"{reg_data_root}\" \\\n",
|
190 |
-
" -n \"{config.project_name}\" \\\n",
|
191 |
-
" --gpus 0, \\\n",
|
192 |
-
" --data_root \"/workspace/Dreambooth-Stable-Diffusion/training_images\" \\\n",
|
193 |
-
" --max_training_steps {config.max_training_steps} \\\n",
|
194 |
-
" --class_word \"{config.class_word}\" \\\n",
|
195 |
-
" --token \"{config.token}\" \\\n",
|
196 |
-
" --no-test \\\n",
|
197 |
-
" --flip_p {config.flip_percent} \\\n",
|
198 |
-
" --learning_rate {config.learning_rate} \\\n",
|
199 |
-
" --save_every_x_steps {config.save_every_x_steps}"
|
200 |
-
]
|
201 |
-
},
|
202 |
-
{
|
203 |
-
"cell_type": "markdown",
|
204 |
-
"metadata": {},
|
205 |
-
"source": [
|
206 |
-
"## Copy and name the checkpoint file(s)"
|
207 |
-
]
|
208 |
-
},
|
209 |
-
{
|
210 |
-
"cell_type": "code",
|
211 |
-
"execution_count": null,
|
212 |
-
"metadata": {
|
213 |
-
"pycharm": {
|
214 |
-
"is_executing": true
|
215 |
-
}
|
216 |
-
},
|
217 |
-
"outputs": [],
|
218 |
-
"source": [
|
219 |
-
"from JupyterNotebookHelpers.copy_and_name_checkpoints import CopyAndNameCheckpoints\n",
|
220 |
-
"\n",
|
221 |
-
"active_config_path = \"./joepenna-dreambooth-configs/active-config.json\"\n",
|
222 |
-
"\n",
|
223 |
-
"copy_and_name_checkpoints = CopyAndNameCheckpoints()\n",
|
224 |
-
"copy_and_name_checkpoints.execute(\n",
|
225 |
-
" active_config_path=active_config_path,\n",
|
226 |
-
" output_folder=\"./trained_models\"\n",
|
227 |
-
")"
|
228 |
-
]
|
229 |
-
},
|
230 |
-
{
|
231 |
-
"cell_type": "markdown",
|
232 |
-
"metadata": {},
|
233 |
-
"source": [
|
234 |
-
"# Optional - Upload to google drive\n",
|
235 |
-
"* run the following commands in a new `terminal` in the `Dreambooth-Stable-Diffusion` directory\n",
|
236 |
-
"* `chmod +x ./gdrive`\n",
|
237 |
-
"* `./gdrive about`\n",
|
238 |
-
"* `paste your token here after navigating to the link`\n",
|
239 |
-
"* `./gdrive upload trained_models/{file_name.ckpt}`"
|
240 |
-
]
|
241 |
-
},
|
242 |
-
{
|
243 |
-
"cell_type": "markdown",
|
244 |
-
"metadata": {},
|
245 |
-
"source": [
|
246 |
-
"# Big Important Note!\n",
|
247 |
-
"\n",
|
248 |
-
"The way to use your token is `<token> <class>` ie `joepenna person` and not just `joepenna`"
|
249 |
-
]
|
250 |
-
}
|
251 |
-
],
|
252 |
-
"metadata": {
|
253 |
-
"kernelspec": {
|
254 |
-
"display_name": "Python 3 (ipykernel)",
|
255 |
-
"language": "python",
|
256 |
-
"name": "python3"
|
257 |
-
},
|
258 |
-
"language_info": {
|
259 |
-
"codemirror_mode": {
|
260 |
-
"name": "ipython",
|
261 |
-
"version": 3
|
262 |
-
},
|
263 |
-
"file_extension": ".py",
|
264 |
-
"mimetype": "text/x-python",
|
265 |
-
"name": "python",
|
266 |
-
"nbconvert_exporter": "python",
|
267 |
-
"pygments_lexer": "ipython3",
|
268 |
-
"version": "3.10.7"
|
269 |
-
}
|
270 |
-
},
|
271 |
-
"nbformat": 4,
|
272 |
-
"nbformat_minor": 1
|
273 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|