TheLastBen
commited on
Commit
•
37bd07b
1
Parent(s):
87b6ac9
Update Scripts/mainpaperspacev2.py
Browse files- Scripts/mainpaperspacev2.py +20 -25
Scripts/mainpaperspacev2.py
CHANGED
@@ -21,7 +21,6 @@ from math import log, sqrt
|
|
21 |
import numpy as np
|
22 |
|
23 |
|
24 |
-
|
25 |
def Deps(force_reinstall):
|
26 |
|
27 |
if not force_reinstall and os.path.exists('/usr/local/lib/python3.9/dist-packages/safetensors'):
|
@@ -59,8 +58,8 @@ def Deps(force_reinstall):
|
|
59 |
clear_output()
|
60 |
|
61 |
done()
|
62 |
-
|
63 |
-
|
64 |
def ntbk():
|
65 |
|
66 |
os.chdir('/notebooks')
|
@@ -146,13 +145,12 @@ def downloadmodel_lnkv2(CKPT_Link, Custom_Model_Version):
|
|
146 |
|
147 |
if os.path.exists('model.ckpt'):
|
148 |
if os.path.getsize("model.ckpt") > 1810671599:
|
149 |
-
wget.download('https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/Dreambooth/convertodiffv2.py')
|
150 |
if Custom_Model_Version=='512':
|
|
|
151 |
call('python convertodiffv2.py model.ckpt stable-diffusion-custom --v2 --reference_model stabilityai/stable-diffusion-2-1-base', shell=True)
|
152 |
elif Custom_Model_Version=='768':
|
|
|
153 |
call('python convertodiffv2.py model.ckpt stable-diffusion-custom --v2 --reference_model stabilityai/stable-diffusion-2-1', shell=True)
|
154 |
-
#if os.path.exists('stable-diffusion-custom/unet/diffusion_pytorch_model.bin'):
|
155 |
-
#call('wget -q -O stable-diffusion-custom/unet/config.json https://huggingface.co/stabilityai/stable-diffusion-2-1/raw/main/unet/config.json', shell=True)
|
156 |
call('rm convertodiffv2.py', shell=True)
|
157 |
if os.path.exists('stable-diffusion-custom/unet/diffusion_pytorch_model.bin'):
|
158 |
call('rm model.ckpt', shell=True)
|
@@ -170,8 +168,7 @@ def downloadmodel_lnkv2(CKPT_Link, Custom_Model_Version):
|
|
170 |
os.chdir('/notebooks')
|
171 |
time.sleep(5)
|
172 |
|
173 |
-
|
174 |
-
|
175 |
|
176 |
def dlv2(Path_to_HuggingFace, CKPT_Path, CKPT_Link, Model_Version, Custom_Model_Version):
|
177 |
|
@@ -275,17 +272,16 @@ def sessv2(Session_Name, Session_Link_optional, Model_Version, MODEL_NAMEv2):
|
|
275 |
|
276 |
elif os.path.exists(MDLPTH):
|
277 |
print('[1;32mSession found, loading the trained model ...')
|
278 |
-
call('wget -q -O convertodiff.py https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/Dreambooth/convertodiffv2.py', shell=True)
|
279 |
if Model_Version=='512':
|
|
|
280 |
print('[1;32mSession found, loading the trained model ...')
|
281 |
call('python convertodiff.py '+MDLPTH+' '+OUTPUT_DIR+' --v2 --reference_model stabilityai/stable-diffusion-2-1-base', shell=True)
|
282 |
elif Model_Version=='768':
|
|
|
283 |
print('[1;32mSession found, loading the trained model ...')
|
284 |
call('python convertodiff.py '+MDLPTH+' '+OUTPUT_DIR+' --v2 --reference_model stabilityai/stable-diffusion-2-1', shell=True)
|
285 |
-
|
286 |
-
call('wget -q -O '+OUTPUT_DIR+'/unet/config.json https://huggingface.co/stabilityai/stable-diffusion-2-1/raw/main/unet/config.json', shell=True)
|
287 |
call('rm convertodiff.py', shell=True)
|
288 |
-
|
289 |
if os.path.exists(OUTPUT_DIR+'/unet/diffusion_pytorch_model.bin'):
|
290 |
resumev2=True
|
291 |
clear_output()
|
@@ -302,9 +298,9 @@ def sessv2(Session_Name, Session_Link_optional, Model_Version, MODEL_NAMEv2):
|
|
302 |
print('[1;32mSession created, proceed to uploading instance images')
|
303 |
|
304 |
return PT, WORKSPACE, Session_Name, INSTANCE_NAME, OUTPUT_DIR, SESSION_DIR, CONCEPT_DIR, INSTANCE_DIR, CAPTIONS_DIR, MDLPTH, MODEL_NAMEv2, resumev2
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
def done():
|
309 |
done = widgets.Button(
|
310 |
description='Done!',
|
@@ -314,10 +310,9 @@ def done():
|
|
314 |
icon='check'
|
315 |
)
|
316 |
display(done)
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
def uplder(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDER_OPTIONAL, INSTANCE_DIR, CAPTIONS_DIR, ren):
|
322 |
|
323 |
if os.path.exists(INSTANCE_DIR+"/.ipynb_checkpoints"):
|
@@ -347,7 +342,7 @@ def uplder(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDE
|
|
347 |
else:
|
348 |
upld(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDER_OPTIONAL, INSTANCE_DIR, CAPTIONS_DIR, uploader, ren)
|
349 |
done()
|
350 |
-
|
351 |
|
352 |
def upld(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDER_OPTIONAL, INSTANCE_DIR, CAPTIONS_DIR, uploader, ren):
|
353 |
|
@@ -455,8 +450,9 @@ def upld(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDER_
|
|
455 |
os.chdir(CAPTIONS_DIR)
|
456 |
call('find . -name "* *" -type f | rename ' "'s/ /-/g'", shell=True)
|
457 |
os.chdir('/notebooks')
|
458 |
-
|
459 |
-
|
|
|
460 |
def caption(CAPTIONS_DIR, INSTANCE_DIR):
|
461 |
|
462 |
paths=""
|
@@ -520,9 +516,8 @@ def caption(CAPTIONS_DIR, INSTANCE_DIR):
|
|
520 |
widgets_l.observe(click, names='value')
|
521 |
display(widgets.HBox([widgets_l, out]))
|
522 |
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
def dbtrainv2(Resume_Training, UNet_Training_Steps, UNet_Learning_Rate, Text_Encoder_Training_Steps, Text_Encoder_Concept_Training_Steps, Text_Encoder_Learning_Rate, Offset_Noise, Resolution, MODEL_NAMEv2, SESSION_DIR, INSTANCE_DIR, CONCEPT_DIR, CAPTIONS_DIR, External_Captions, INSTANCE_NAME, Session_Name, OUTPUT_DIR, PT, resumev2, Save_Checkpoint_Every_n_Steps, Start_saving_from_the_step, Save_Checkpoint_Every):
|
527 |
|
528 |
if os.path.exists(INSTANCE_DIR+"/.ipynb_checkpoints"):
|
|
|
21 |
import numpy as np
|
22 |
|
23 |
|
|
|
24 |
def Deps(force_reinstall):
|
25 |
|
26 |
if not force_reinstall and os.path.exists('/usr/local/lib/python3.9/dist-packages/safetensors'):
|
|
|
58 |
clear_output()
|
59 |
|
60 |
done()
|
61 |
+
|
62 |
+
|
63 |
def ntbk():
|
64 |
|
65 |
os.chdir('/notebooks')
|
|
|
145 |
|
146 |
if os.path.exists('model.ckpt'):
|
147 |
if os.path.getsize("model.ckpt") > 1810671599:
|
|
|
148 |
if Custom_Model_Version=='512':
|
149 |
+
call('wget -q -O convertodiffv2.py https://github.com/TheLastBen/fast-stable-diffusion/raw/main/Dreambooth/convertodiffv2.py', shell=True)
|
150 |
call('python convertodiffv2.py model.ckpt stable-diffusion-custom --v2 --reference_model stabilityai/stable-diffusion-2-1-base', shell=True)
|
151 |
elif Custom_Model_Version=='768':
|
152 |
+
call('wget -q -O convertodiffv2.py https://github.com/TheLastBen/fast-stable-diffusion/raw/main/Dreambooth/convertodiffv2-768.py', shell=True)
|
153 |
call('python convertodiffv2.py model.ckpt stable-diffusion-custom --v2 --reference_model stabilityai/stable-diffusion-2-1', shell=True)
|
|
|
|
|
154 |
call('rm convertodiffv2.py', shell=True)
|
155 |
if os.path.exists('stable-diffusion-custom/unet/diffusion_pytorch_model.bin'):
|
156 |
call('rm model.ckpt', shell=True)
|
|
|
168 |
os.chdir('/notebooks')
|
169 |
time.sleep(5)
|
170 |
|
171 |
+
|
|
|
172 |
|
173 |
def dlv2(Path_to_HuggingFace, CKPT_Path, CKPT_Link, Model_Version, Custom_Model_Version):
|
174 |
|
|
|
272 |
|
273 |
elif os.path.exists(MDLPTH):
|
274 |
print('[1;32mSession found, loading the trained model ...')
|
|
|
275 |
if Model_Version=='512':
|
276 |
+
call('wget -q -O convertodiff.py https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/Dreambooth/convertodiffv2.py', shell=True)
|
277 |
print('[1;32mSession found, loading the trained model ...')
|
278 |
call('python convertodiff.py '+MDLPTH+' '+OUTPUT_DIR+' --v2 --reference_model stabilityai/stable-diffusion-2-1-base', shell=True)
|
279 |
elif Model_Version=='768':
|
280 |
+
call('wget -q -O convertodiff.py https://github.com/TheLastBen/fast-stable-diffusion/raw/main/Dreambooth/convertodiffv2-768.py', shell=True)
|
281 |
print('[1;32mSession found, loading the trained model ...')
|
282 |
call('python convertodiff.py '+MDLPTH+' '+OUTPUT_DIR+' --v2 --reference_model stabilityai/stable-diffusion-2-1', shell=True)
|
283 |
+
|
|
|
284 |
call('rm convertodiff.py', shell=True)
|
|
|
285 |
if os.path.exists(OUTPUT_DIR+'/unet/diffusion_pytorch_model.bin'):
|
286 |
resumev2=True
|
287 |
clear_output()
|
|
|
298 |
print('[1;32mSession created, proceed to uploading instance images')
|
299 |
|
300 |
return PT, WORKSPACE, Session_Name, INSTANCE_NAME, OUTPUT_DIR, SESSION_DIR, CONCEPT_DIR, INSTANCE_DIR, CAPTIONS_DIR, MDLPTH, MODEL_NAMEv2, resumev2
|
301 |
+
|
302 |
+
|
303 |
+
|
304 |
def done():
|
305 |
done = widgets.Button(
|
306 |
description='Done!',
|
|
|
310 |
icon='check'
|
311 |
)
|
312 |
display(done)
|
313 |
+
|
314 |
+
|
315 |
+
|
|
|
316 |
def uplder(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDER_OPTIONAL, INSTANCE_DIR, CAPTIONS_DIR, ren):
|
317 |
|
318 |
if os.path.exists(INSTANCE_DIR+"/.ipynb_checkpoints"):
|
|
|
342 |
else:
|
343 |
upld(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDER_OPTIONAL, INSTANCE_DIR, CAPTIONS_DIR, uploader, ren)
|
344 |
done()
|
345 |
+
|
346 |
|
347 |
def upld(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDER_OPTIONAL, INSTANCE_DIR, CAPTIONS_DIR, uploader, ren):
|
348 |
|
|
|
450 |
os.chdir(CAPTIONS_DIR)
|
451 |
call('find . -name "* *" -type f | rename ' "'s/ /-/g'", shell=True)
|
452 |
os.chdir('/notebooks')
|
453 |
+
|
454 |
+
|
455 |
+
|
456 |
def caption(CAPTIONS_DIR, INSTANCE_DIR):
|
457 |
|
458 |
paths=""
|
|
|
516 |
widgets_l.observe(click, names='value')
|
517 |
display(widgets.HBox([widgets_l, out]))
|
518 |
|
519 |
+
|
520 |
+
|
|
|
521 |
def dbtrainv2(Resume_Training, UNet_Training_Steps, UNet_Learning_Rate, Text_Encoder_Training_Steps, Text_Encoder_Concept_Training_Steps, Text_Encoder_Learning_Rate, Offset_Noise, Resolution, MODEL_NAMEv2, SESSION_DIR, INSTANCE_DIR, CONCEPT_DIR, CAPTIONS_DIR, External_Captions, INSTANCE_NAME, Session_Name, OUTPUT_DIR, PT, resumev2, Save_Checkpoint_Every_n_Steps, Start_saving_from_the_step, Save_Checkpoint_Every):
|
522 |
|
523 |
if os.path.exists(INSTANCE_DIR+"/.ipynb_checkpoints"):
|