TheLastBen commited on
Commit
60481dc
1 Parent(s): 8427536

Upload sdxllorapps.py

Browse files
Files changed (1) hide show
  1. Scripts/sdxllorapps.py +33 -6
Scripts/sdxllorapps.py CHANGED
@@ -21,6 +21,7 @@ import fileinput
21
  import six
22
  import base64
23
  import re
 
24
 
25
  from urllib.parse import urlparse, parse_qs, unquote
26
  import urllib.request
@@ -416,7 +417,7 @@ def sess_xl(Session_Name, MODEL_NAMExl):
416
 
417
 
418
 
419
- def uplder(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDER_OPTIONAL, INSTANCE_DIR, CAPTIONS_DIR):
420
 
421
  if os.path.exists(INSTANCE_DIR+"/.ipynb_checkpoints"):
422
  call('rm -r '+INSTANCE_DIR+'/.ipynb_checkpoints', shell=True)
@@ -435,7 +436,7 @@ def uplder(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDE
435
  with out:
436
  uploader.close()
437
  Upload.close()
438
- upld(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDER_OPTIONAL, INSTANCE_DIR, CAPTIONS_DIR, uploader)
439
  done()
440
  out=widgets.Output()
441
 
@@ -443,12 +444,12 @@ def uplder(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDE
443
  Upload.on_click(up)
444
  display(uploader, Upload, out)
445
  else:
446
- upld(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDER_OPTIONAL, INSTANCE_DIR, CAPTIONS_DIR, uploader)
447
  done()
448
 
449
 
450
 
451
- def upld(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDER_OPTIONAL, INSTANCE_DIR, CAPTIONS_DIR, uploader):
452
 
453
 
454
  if Remove_existing_instance_images:
@@ -547,7 +548,9 @@ def upld(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDER_
547
  os.chdir(CAPTIONS_DIR)
548
  call('find . -name "* *" -type f | rename ' "'s/ /-/g'", shell=True)
549
  os.chdir('/notebooks')
550
-
 
 
551
 
552
 
553
 
@@ -616,7 +619,7 @@ def caption(CAPTIONS_DIR, INSTANCE_DIR):
616
 
617
 
618
 
619
- def dbtrainxl(Unet_Training_Epochs, Text_Encoder_Training_Epochs, Unet_Learning_Rate, Text_Encoder_Learning_Rate, dim, Offset_Noise, Resolution, MODEL_NAME, SESSION_DIR, INSTANCE_DIR, CAPTIONS_DIR, External_Captions, INSTANCE_NAME, Session_Name, OUTPUT_DIR, ofstnselvl, Save_VRAM):
620
 
621
 
622
  if os.path.exists(INSTANCE_DIR+"/.ipynb_checkpoints"):
@@ -674,6 +677,7 @@ def dbtrainxl(Unet_Training_Epochs, Text_Encoder_Training_Epochs, Unet_Learning_
674
  call('accelerate launch /notebooks/diffusers/examples/dreambooth/train_dreambooth_sdxl_lora.py \
675
  '+ofstnse+' \
676
  '+extrnlcptn+' \
 
677
  --dim='+str(dim)+' \
678
  --ofstnselvl='+str(ofstnselvl)+' \
679
  --image_captions_filename \
@@ -1111,6 +1115,29 @@ def crop_image(im, size):
1111
 
1112
  return results
1113
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1114
 
1115
 
1116
  def clean_symlinks(path):
 
21
  import six
22
  import base64
23
  import re
24
+ import cv2
25
 
26
  from urllib.parse import urlparse, parse_qs, unquote
27
  import urllib.request
 
417
 
418
 
419
 
420
+ def uplder(Remove_existing_instance_images, Crop_images, Crop_size, Resize_to_1024_and_keep_aspect_ratio, IMAGES_FOLDER_OPTIONAL, INSTANCE_DIR, CAPTIONS_DIR):
421
 
422
  if os.path.exists(INSTANCE_DIR+"/.ipynb_checkpoints"):
423
  call('rm -r '+INSTANCE_DIR+'/.ipynb_checkpoints', shell=True)
 
436
  with out:
437
  uploader.close()
438
  Upload.close()
439
+ upld(Remove_existing_instance_images, Crop_images, Crop_size, Resize_to_1024_and_keep_aspect_ratio, IMAGES_FOLDER_OPTIONAL, INSTANCE_DIR, CAPTIONS_DIR, uploader)
440
  done()
441
  out=widgets.Output()
442
 
 
444
  Upload.on_click(up)
445
  display(uploader, Upload, out)
446
  else:
447
+ upld(Remove_existing_instance_images, Crop_images, Crop_size, Resize_to_1024_and_keep_aspect_ratio, IMAGES_FOLDER_OPTIONAL, INSTANCE_DIR, CAPTIONS_DIR, uploader)
448
  done()
449
 
450
 
451
 
452
+ def upld(Remove_existing_instance_images, Crop_images, Crop_size, Resize_to_1024_and_keep_aspect_ratio, IMAGES_FOLDER_OPTIONAL, INSTANCE_DIR, CAPTIONS_DIR, uploader):
453
 
454
 
455
  if Remove_existing_instance_images:
 
548
  os.chdir(CAPTIONS_DIR)
549
  call('find . -name "* *" -type f | rename ' "'s/ /-/g'", shell=True)
550
  os.chdir('/notebooks')
551
+
552
+ if Resize_to_1024_and_keep_aspect_ratio and not Crop_images:
553
+ resize_keep_aspect(INSTANCE_DIR)
554
 
555
 
556
 
 
619
 
620
 
621
 
622
+ def dbtrainxl(Unet_Training_Epochs, Text_Encoder_Training_Epochs, Unet_Learning_Rate, Text_Encoder_Learning_Rate, dim, Offset_Noise, Resolution, MODEL_NAME, SESSION_DIR, INSTANCE_DIR, CAPTIONS_DIR, External_Captions, INSTANCE_NAME, Session_Name, OUTPUT_DIR, ofstnselvl, Save_VRAM, Intermediary_Save_Epoch):
623
 
624
 
625
  if os.path.exists(INSTANCE_DIR+"/.ipynb_checkpoints"):
 
677
  call('accelerate launch /notebooks/diffusers/examples/dreambooth/train_dreambooth_sdxl_lora.py \
678
  '+ofstnse+' \
679
  '+extrnlcptn+' \
680
+ --saves='+Intermediary_Save_Epoch+' \
681
  --dim='+str(dim)+' \
682
  --ofstnselvl='+str(ofstnselvl)+' \
683
  --image_captions_filename \
 
1115
 
1116
  return results
1117
 
1118
+
1119
+
1120
+ def resize_keep_aspect(DIR):
1121
+
1122
+ min_dimension=1024
1123
+
1124
+ for filename in os.listdir(DIR):
1125
+ if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.webp')):
1126
+ image = cv2.imread(os.path.join(DIR, filename))
1127
+
1128
+ org_height, org_width = image.shape[0], image.shape[1]
1129
+
1130
+ if org_width < org_height:
1131
+ new_width = min_dimension
1132
+ new_height = int(org_height * (min_dimension / org_width))
1133
+ else:
1134
+ new_height = min_dimension
1135
+ new_width = int(org_width * (min_dimension / org_height))
1136
+
1137
+ resized_image = cv2.resize(image, (new_width, new_height), interpolation=cv2.INTER_LANCZOS4)
1138
+
1139
+ cv2.imwrite(os.path.join(DIR, filename), resized_image, [int(cv2.IMWRITE_PNG_COMPRESSION), 0])
1140
+
1141
 
1142
 
1143
  def clean_symlinks(path):