Skip to content

Commit d3fa43a

Browse files
author
Werner Oswald
committed
less bugs,
add a multi model prompt loop
1 parent 3f9aa9b commit d3fa43a

18 files changed

+386
-313
lines changed

backend/deforum/deforum_adapter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ def load_model_from_config(self, config=None, ckpt=None, verbose=False):
292292

293293
# gs.model_version = config.model_version
294294
if verbose:
295-
print(gs.model_version)
295+
print('gs.model_version', gs.model_version)
296296

297297
checkpoint_file = ckpt
298298
_, extension = os.path.splitext(checkpoint_file)

backend/deforum/six/generate.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def create_random_tensors(shape, seeds, subseeds=None, subseed_strength=0.0, see
8080
sampler_noises = [[] for _ in range(p.sampler.number_of_needed_noises(p))]
8181
else:
8282
sampler_noises = None
83-
print(type(seeds))
83+
print('type(seeds)', type(seeds))
8484
for i, seed in enumerate(seeds):
8585
noise_shape = shape if seed_resize_from_h <= 0 or seed_resize_from_w <= 0 else (
8686
shape[0], seed_resize_from_h // 8, seed_resize_from_w // 8)
@@ -250,7 +250,7 @@ def generate(args, root, frame=0, return_latent=False, return_sample=False, retu
250250
sampler = PLMSSampler(gs.models["sd"]) if args.sampler == 'plms' else DDIMSampler(gs.models["sd"])
251251
if gs.model_version in gs.system.gen_one_models or gs.model_resolution == 512:
252252
model_wrap = CompVisDenoiser(gs.models["sd"])
253-
print(gs.model_version, gs.model_resolution)
253+
print('gs.model_version, gs.model_resolution', gs.model_version, gs.model_resolution)
254254
elif gs.model_version in gs.system.gen_two_models and gs.model_resolution == 768:
255255
gs.denoiser = 2
256256
model_wrap = CompVisVDenoiser(gs.models["sd"])

backend/deforum/six/model_load.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ def load_model_from_config(config, ckpt, verbose=False, device='cuda', half_prec
189189
m, u = model.load_state_dict(sd, strict=False)
190190
if print_flag:
191191
if len(m) > 0 and verbose:
192-
print("missing keys:")
193-
print(m)
192+
print("missing keys:", m)
193+
print('mmissing keys ', m)
194194
if len(u) > 0 and verbose:
195195
print("unexpected keys:")
196196
print(u)

backend/deforum/six/render.py

+27-4
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434

3535

3636
def next_seed(args):
37-
print(type(args.seed))
38-
print(args.seed)
37+
print('type(args.seed)', type(args.seed))
38+
print('args.seed',args.seed)
3939
args.seed = int(args.seed)
4040
if args.seed_behavior == 'iter':
4141
args.seed += 1
@@ -62,6 +62,24 @@ def save_settings(args, outfolder, prompt, index):
6262
del output_data
6363

6464

65+
def shorten_path(path):
66+
# Get the directory, filename, and extension
67+
dir_name, filename = os.path.split(path)
68+
name, ext = os.path.splitext(filename)
69+
70+
# Shorten the name if necessary
71+
max_length = 250 - len(ext)
72+
if len(name) > max_length:
73+
name = name[:max_length]
74+
75+
# Join the shortened name and extension
76+
shortened_filename = name + ext
77+
78+
# Join the shortened filename and directory to get the shortened path
79+
shortened_path = os.path.join(dir_name, shortened_filename)
80+
81+
return shortened_path
82+
6583
def render_image_batch(args, prompts, root, image_callback=None, step_callback=None):
6684
args.prompts = {k: f"{v:05d}" for v, k in enumerate(prompts)}
6785

@@ -179,11 +197,16 @@ def render_image_batch(args, prompts, root, image_callback=None, step_callback=N
179197
filename = f"{args.timestring}_{index:05}_{args.seed}.png"
180198
#added prompt to output folder name
181199
if gs.diffusion.pathmode == "prompt-folders":
182-
outfolder = os.path.join(args.outdir, f'{args.timestring}_{sanitize(prompt)[:120]}')
200+
outfolder = os.path.join(args.outdir, f'{args.timestring}_{sanitize(prompt)[:80]}')
183201
else:
184202
outfolder = os.path.join(args.outdir, datetime.now().strftime("%Y%m%d"))
185203
os.makedirs(outfolder, exist_ok=True)
186-
gs.temppath = os.path.join(outfolder, filename)
204+
abs_path = os.path.join(outfolder, filename)
205+
if len(abs_path) > 250:
206+
print('path to long and gets shortened')
207+
abs_path = shorten_path(abs_path)
208+
209+
gs.temppath = abs_path
187210
if args.save_samples:
188211
paths.append(gs.temppath)
189212
image.save(gs.temppath)

backend/modelloader.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,15 @@ def load_model_from_config(config, ckpt, verbose=False):
8484

8585
model = instantiate_from_config(config.model)
8686
m, u = model.load_state_dict(sd, strict=False)
87-
print(m[0])
88-
print(u[0])
87+
print('m[0]', m[0])
88+
print('u[0]', u[0])
8989

9090
if len(m) > 0 and verbose:
91-
print("missing keys:")
92-
print(m)
91+
print("missing keys:", m)
92+
9393
if len(u) > 0 and verbose:
94-
print("unexpected keys:")
95-
print(u)
94+
print("unexpected keys:", u)
95+
9696

9797
model.cuda()
9898
model.eval()

backend/poor_mans_wget.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,15 @@ def wget_progress(url, filename, length=0, chunk_size=8192, callback=None):
4141
downloaded_bytes = 0
4242
callback(next_percent)
4343
with open(filename, 'wb') as f:
44-
for chunk in r.iter_content(chunk_size=8192):
45-
# If you have chunk encoded response uncomment if
46-
# and set chunk_size parameter to None.
47-
#if chunk:
48-
f.write(chunk)
49-
downloaded_bytes += chunk_size
50-
if downloaded_bytes > next_percent * one_percent:
51-
next_percent += 1
52-
callback(next_percent)
44+
try:
45+
for chunk in r.iter_content(chunk_size=8192):
46+
# If you have chunk encoded response uncomment if
47+
# and set chunk_size parameter to None.
48+
#if chunk:
49+
f.write(chunk)
50+
downloaded_bytes += chunk_size
51+
if downloaded_bytes > next_percent * one_percent:
52+
next_percent += 1
53+
callback(next_percent)
54+
except Exception as e:
55+
print('error while writing download file: ', e)

configs/ainodes/colab_settings.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@
164164
"selected_aesthetic_embedding": "None",
165165
"multi_dim_prompt": false,
166166
"multi_dim_seed_behavior": 0,
167-
"hires_strength": 0.0
167+
"hires_strength": 0.0,
168+
"multi_model_batch": false,
169+
"multi_model_list": []
168170
}
169171
}

configs/ainodes/default_settings.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@
169169
"multi_dim_prompt": false,
170170
"multi_dim_seed_behavior": 0,
171171
"hires_strength": 0.0,
172-
"preview_mode": 0
172+
"preview_mode": 0,
173+
"multi_model_batch": false,
174+
"multi_model_list": []
173175
}
174176
}

documentation/Documentation.odt

17 KB
Binary file not shown.

frontend/mainwindow.py

-38
Original file line numberDiff line numberDiff line change
@@ -1068,9 +1068,7 @@ def add_next_rect(self, h, w):
10681068
if i.id == self.canvas.canvas.render_item:
10691069
w = self.canvas.canvas.rectlist[self.canvas.canvas.rectlist.index(i)].w
10701070
x = self.canvas.canvas.rectlist[self.canvas.canvas.rectlist.index(i)].x + w + 20
1071-
print(f"w, x: {w}, {x}")
10721071
y = i.y
1073-
# print(i.x + w, i.y, self.cheight, self.w, self.stopwidth)
10741072
if x > 3000:
10751073
x = 0
10761074
y = self.cheight + 25
@@ -1125,42 +1123,6 @@ def tensor_preview_schedule(self): # TODO: Rename this function to tensor_draw_
11251123
except:
11261124
pass
11271125

1128-
def is_multiple_of_512(num):
1129-
if num % 512 == 0:
1130-
return True
1131-
else:
1132-
return False
1133-
1134-
def nearest_multiple_of_512(num):
1135-
quotient = num // 512
1136-
lower_multiple = quotient * 512
1137-
upper_multiple = (quotient + 1) * 512
1138-
if abs(num - lower_multiple) < abs(num - upper_multiple):
1139-
return lower_multiple
1140-
else:
1141-
return upper_multiple
1142-
1143-
# not used ???
1144-
def prep_rect_params_(self, prompt=None):
1145-
# prompt = str(prompt)
1146-
# steps = self.widgets[self.current_widget].w.stepsSlider.value()
1147-
params = {"prompts": self.widgets[self.current_widget].w.prompts.toPlainText(),
1148-
"seed": random.randint(0, 2 ** 32 - 1) if self.widgets[
1149-
self.current_widget].w.seed.text() == '' else int(
1150-
self.widgets[self.current_widget].w.seed.text()),
1151-
"strength": self.widgets[self.current_widget].w.strength.value(),
1152-
"scale": self.widgets[self.current_widget].w.scale.value(),
1153-
"mask_blur": int(self.widgets[self.current_widget].w.mask_blur.value()),
1154-
"reconstruction_blur": int(self.widgets[self.current_widget].w.recons_blur.value()),
1155-
"with_inpaint": self.widgets[self.current_widget].w.with_inpaint.isChecked(),
1156-
"mask_offset": self.widgets[self.current_widget].w.mask_offset.value(),
1157-
"steps": self.widgets[self.current_widget].w.steps.value(),
1158-
"H": self.widgets[self.current_widget].w.H.value(),
1159-
"W": self.widgets[self.current_widget].w.W.value(),
1160-
"ddim_eta": self.widgets[self.current_widget].w.ddim_eta.value()
1161-
}
1162-
1163-
return params
11641126

11651127
@Slot(object)
11661128
def draw_tempRects_signal(self, values):

frontend/session_params.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,18 @@ def update_params(self, update_db=True):
123123

124124
outdir = gs.system.txt2img_out_dir
125125
use_mask = self.parent.widgets[widget].w.use_mask.isChecked()
126+
multi_model_batch = self.parent.widgets[widget].w.toggle_multi_model_batch.isChecked()
127+
multi_model_list = []
128+
129+
selected_multi_model_batch = self.parent.widgets[widget].w.multi_model_batch_list.selectedItems()
130+
if len(selected_multi_model_batch) > 0:
131+
for item in selected_multi_model_batch:
132+
multi_model_list.append(item.text())
133+
134+
126135
if self.parent.widgets[widget].w.max_frames.value() < 2:
127136
animation_mode = 'None'
128137

129-
130138
use_alpha_as_mask = self.parent.widgets[widget].w.use_alpha_as_mask_2.isChecked()
131139
mask_file = self.parent.widgets[widget].w.mask_file.text()
132140
invert_mask = self.parent.widgets[widget].w.invert_mask_2.isChecked()
@@ -135,7 +143,6 @@ def update_params(self, update_db=True):
135143
mask_overlay_blur = self.parent.widgets[widget].w.mask_overlay_blur_2.value()
136144
overlay_mask = self.parent.widgets[widget].w.overlay_mask_2.isChecked()
137145

138-
139146
else:
140147

141148
use_alpha_as_mask = self.parent.widgets[widget].w.use_alpha_as_mask.isChecked()
@@ -145,6 +152,8 @@ def update_params(self, update_db=True):
145152
mask_contrast_adjust = self.parent.widgets[widget].w.mask_contrast_adjust.value()
146153
mask_overlay_blur = self.parent.widgets[widget].w.mask_overlay_blur.value()
147154
overlay_mask = self.parent.widgets[widget].w.overlay_mask.isChecked()
155+
multi_model_batch = False
156+
multi_model_list = []
148157

149158
if self.parent.widgets[widget].w.anim2D.isChecked():
150159
animation_mode = '2D'
@@ -323,6 +332,8 @@ def update_params(self, update_db=True):
323332
"karras_sigma_max": self.parent.widgets[widget].w.karras_sigma_max.value(),
324333
"pathmode": self.parent.widgets[widget].w.pathmode.currentText(),
325334
"discard_next_to_last_sigma": self.parent.widgets[widget].w.discard_next_to_last_sigma.isChecked(),
335+
"multi_model_batch": multi_model_batch,
336+
"multi_model_list": multi_model_list
326337
}
327338

328339
self.update_diffusion_settings(update_db=update_db)

0 commit comments

Comments
 (0)