update xyz grid

This commit is contained in:
Vladimir Mandic
2024-09-25 19:32:57 -04:00
parent 2c990b73c6
commit 3d38f6ea73
8 changed files with 36 additions and 15 deletions
+4 -1
View File
@@ -328,7 +328,10 @@ class Script(scripts.Script):
grid_count = z_count + ( 1 if not no_grid and z_count > 1 else 0 )
for g in range(grid_count):
adj_g = g-1 if g > 0 else g
images.save_image(processed.images[g], p.outpath_grids, "xyz_grid", info=processed.infotexts[g], extension=shared.opts.grid_format, prompt=processed.all_prompts[adj_g], seed=processed.all_seeds[adj_g], grid=True, p=processed)
info = processed.infotexts[g]
prompt = processed.all_prompts[adj_g]
seed = processed.all_seeds[adj_g]
images.save_image(processed.images[g], p.outpath_grids, "grid", info=info, extension=shared.opts.grid_format, prompt=prompt, seed=seed, grid=True, p=processed)
if not include_sub_grids: # Done with sub-grids, drop all related information:
for _sg in range(z_count):
del processed.images[1]
+2 -2
View File
@@ -1,4 +1,4 @@
from scripts.xyz_grid_shared import apply_field, apply_task_args, apply_setting, apply_prompt, apply_order, apply_sampler, apply_hr_sampler_name, confirm_samplers, apply_checkpoint, apply_refiner, apply_unet, apply_dict, apply_clip_skip, apply_vae, list_lora, apply_lora, apply_te, apply_styles, apply_upscaler, apply_context, apply_face_restore, apply_override, apply_processing, format_value_add_label, format_value, format_value_join_list, do_nothing, format_nothing, str_permutations # pylint: disable=no-name-in-module
from scripts.xyz_grid_shared import apply_field, apply_task_args, apply_setting, apply_prompt, apply_order, apply_sampler, apply_hr_sampler_name, confirm_samplers, apply_checkpoint, apply_refiner, apply_unet, apply_dict, apply_clip_skip, apply_vae, list_lora, apply_lora, apply_te, apply_styles, apply_upscaler, apply_context, apply_face_restore, apply_override, apply_processing, apply_seed, format_value_add_label, format_value, format_value_join_list, do_nothing, format_nothing, str_permutations # pylint: disable=no-name-in-module
from modules import shared, shared_items, sd_samplers, ipadapter, sd_models, sd_vae, sd_unet
@@ -93,7 +93,7 @@ axis_options = [
AxisOption("[Network] Styles", str, apply_styles, choices=lambda: [s.name for s in shared.prompt_styles.styles.values()]),
AxisOption("[Param] Width", int, apply_field("width")),
AxisOption("[Param] Height", int, apply_field("height")),
AxisOption("[Param] Seed", int, apply_field("seed")),
AxisOption("[Param] Seed", int, apply_seed),
AxisOption("[Param] Steps", int, apply_field("steps")),
AxisOption("[Param] CFG scale", float, apply_field("cfg_scale")),
AxisOption("[Param] Guidance end", float, apply_field("cfg_end")),
+1 -2
View File
@@ -84,9 +84,8 @@ def draw_xyz_grid(p, xs, ys, zs, x_labels, y_labels, z_labels, cell, draw_legend
return processing.Processed(p, [])
t1 = time.time()
z_count = len(zs)
grid = None
for i in range(z_count):
for i in range(len(zs)):
start_index = (i * len(xs) * len(ys)) + i
end_index = start_index + len(xs) * len(ys)
to_process = processed_result.images[start_index:end_index]
+8 -2
View File
@@ -335,15 +335,20 @@ class Script(scripts.Script):
z_count = len(zs)
processed.infotexts[:1+z_count] = grid_infotext[:1+z_count] # Set the grid infotexts to the real ones with extra_generation_params (1 main grid + z_count sub-grids)
if not include_lone_images:
# TODO broken logic to delete sub-images
if no_grid and include_sub_grids:
processed.images = processed.images[:z_count] # we don't have the main grid image, and need zero additional sub-images
else:
processed.images = processed.images[:z_count+1] # we either have the main grid image, or need one sub-images
if shared.opts.grid_save: # Auto-save main and sub-grids:
grid_count = z_count + ( 1 if not no_grid and z_count > 1 else 0 )
grid_count = z_count + (1 if not no_grid and z_count > 1 else 0)
for g in range(grid_count):
adj_g = g-1 if g > 0 else g
images.save_image(processed.images[g], p.outpath_grids, "xyz_grid", info=processed.infotexts[g], extension=shared.opts.grid_format, prompt=processed.all_prompts[adj_g], seed=processed.all_seeds[adj_g], grid=True, p=processed)
info = processed.infotexts[g]
prompt = processed.all_prompts[adj_g]
seed = processed.all_seeds[adj_g]
_fn, _txt, _exif = images.save_image(processed.images[g], p.outpath_grids, "grid", info=info, extension=shared.opts.grid_format, prompt=prompt, seed=seed, grid=True, p=processed)
# TODO broken logic to delete sub-grids
if not include_sub_grids: # Done with sub-grids, drop all related information:
for _sg in range(z_count):
del processed.images[1]
@@ -354,6 +359,7 @@ class Script(scripts.Script):
del processed.infotexts[0]
active = False
cache = processed
# TODO main processing loop auto-creates grid out of all returned images so we end up with grid of grids + images which we don't need, need to skip that
return processed
def process_images(self, p, enabled, x_type, x_values, x_values_dropdown, y_type, y_values, y_values_dropdown, z_type, z_values, z_values_dropdown, csv_mode, draw_legend, no_fixed_seeds, no_grid, include_lone_images, include_sub_grids, margin_size): # pylint: disable=W0221, W0613
+6
View File
@@ -45,6 +45,12 @@ def apply_setting(field):
return fun
def apply_seed(p, x, xs):
p.seed = x
p.all_seeds = None
shared.log.debug(f'XYZ grid apply seed: {x}')
def apply_prompt(p, x, xs):
if xs[0] not in p.prompt and xs[0] not in p.negative_prompt:
shared.log.warning(f"XYZ grid: prompt S/R did not find {xs[0]} in prompt or negative prompt.")