parent
91f54e00d6
commit
895fea03f0
|
@ -29,9 +29,9 @@ class RandomizeScript(scripts.Script):
|
|||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
randomize_enabled, randomize_param_sampler_name, randomize_param_cfg_scale, randomize_param_steps, randomize_param_width, randomize_param_height, randomize_hires, randomize_hires_denoising_strength, randomize_hires_width, randomize_hires_height, randomize_other_use_scale_latent_for_hires_fix, randomize_other_CLIP_stop_at_last_layers, randomize_other_sd_model_checkpoint, randomize_other_sd_hypernetwork, randomize_other_sd_hypernetwork_strength, randomize_other_eta_noise_seed_delta, randomize_other_styles = self._create_ui()
|
||||
randomize_enabled, randomize_param_sampler_name, randomize_param_cfg_scale, randomize_param_steps, randomize_param_width, randomize_param_height, randomize_hires_chance, randomize_hr_hr_upscaler, randomize_hr_hr_scale, randomize_hr_denoising_strength, randomize_other_CLIP_stop_at_last_layers, randomize_other_sd_model_checkpoint, randomize_other_sd_hypernetwork, randomize_other_sd_hypernetwork_strength, randomize_other_eta_noise_seed_delta, randomize_other_styles = self._create_ui()
|
||||
|
||||
return [randomize_enabled, randomize_param_sampler_name, randomize_param_cfg_scale, randomize_param_steps, randomize_param_width, randomize_param_height, randomize_hires, randomize_hires_denoising_strength, randomize_hires_width, randomize_hires_height, randomize_other_use_scale_latent_for_hires_fix, randomize_other_CLIP_stop_at_last_layers, randomize_other_sd_model_checkpoint, randomize_other_sd_hypernetwork, randomize_other_sd_hypernetwork_strength, randomize_other_eta_noise_seed_delta, randomize_other_styles]
|
||||
return [randomize_enabled, randomize_param_sampler_name, randomize_param_cfg_scale, randomize_param_steps, randomize_param_width, randomize_param_height, randomize_hires_chance, randomize_hr_hr_upscaler, randomize_hr_hr_scale, randomize_hr_denoising_strength, randomize_other_CLIP_stop_at_last_layers, randomize_other_sd_model_checkpoint, randomize_other_sd_hypernetwork, randomize_other_sd_hypernetwork_strength, randomize_other_eta_noise_seed_delta, randomize_other_styles]
|
||||
|
||||
def process(
|
||||
self,
|
||||
|
@ -43,11 +43,10 @@ class RandomizeScript(scripts.Script):
|
|||
randomize_param_steps: str,
|
||||
randomize_param_width: str,
|
||||
randomize_param_height: str,
|
||||
randomize_hires: str,
|
||||
randomize_hires_denoising_strength: str,
|
||||
randomize_hires_width: str,
|
||||
randomize_hires_height: str,
|
||||
randomize_other_use_scale_latent_for_hires_fix: str,
|
||||
randomize_hires_chance: str,
|
||||
randomize_hr_hr_upscaler: str,
|
||||
randomize_hr_hr_scale: str,
|
||||
randomize_hr_denoising_strength: str,
|
||||
randomize_other_CLIP_stop_at_last_layers: str,
|
||||
randomize_other_sd_model_checkpoint: str,
|
||||
randomize_other_sd_hypernetwork: str,
|
||||
|
@ -88,11 +87,10 @@ class RandomizeScript(scripts.Script):
|
|||
randomize_param_steps: str,
|
||||
randomize_param_width: str,
|
||||
randomize_param_height: str,
|
||||
randomize_hires: str,
|
||||
randomize_hires_denoising_strength: str,
|
||||
randomize_hires_width: str,
|
||||
randomize_hires_height: str,
|
||||
randomize_other_use_scale_latent_for_hires_fix: str,
|
||||
randomize_hires_chance: str,
|
||||
randomize_hr_hr_upscaler: str,
|
||||
randomize_hr_hr_scale: str,
|
||||
randomize_hr_denoising_strength: str,
|
||||
randomize_other_CLIP_stop_at_last_layers: str,
|
||||
randomize_other_sd_model_checkpoint: str,
|
||||
randomize_other_sd_hypernetwork: str,
|
||||
|
@ -103,65 +101,35 @@ class RandomizeScript(scripts.Script):
|
|||
):
|
||||
if randomize_enabled and isinstance(p, StableDiffusionProcessingTxt2Img):
|
||||
self.CLIP_stop_at_last_layers = opts.CLIP_stop_at_last_layers
|
||||
self.use_scale_latent_for_hires_fix = opts.use_scale_latent_for_hires_fix
|
||||
self.eta_noise_seed_delta = opts.eta_noise_seed_delta
|
||||
# TODO (mmaker): Fix this jank. Don't do this.
|
||||
all_opts = {k: v for k, v in locals().items() if k not in ['self', 'p', 'randomize_enabled', 'batch_number', 'prompts', 'seeds', 'subseeds']}
|
||||
|
||||
# Base params
|
||||
for param, val in self._list_params(all_opts):
|
||||
try:
|
||||
# Backwards compat
|
||||
if param == 'sampler_name' and hasattr(p, 'sampler_index') and not hasattr(p, 'sampler_name'):
|
||||
param = 'sampler_index'
|
||||
|
||||
opt = self._opt({param: val}, p)
|
||||
if opt is not None:
|
||||
if param in ['seed']:
|
||||
setattr(p, 'all_seeds', [self._opt({param: val}, p) for _ in range(0, len(getattr(p, 'all_seeds')))]) # NOTE (mmaker): Is this correct?
|
||||
else:
|
||||
setattr(p, param, opt)
|
||||
else:
|
||||
print(f'Skipping randomizing param `{param}` -- incorrect value')
|
||||
except (TypeError, IndexError) as exception:
|
||||
print(f'Failed to randomize param `{param}` -- incorrect value?', exception)
|
||||
self._set_attr(p, param, val)
|
||||
|
||||
# Other params
|
||||
for param, val in self._list_params(all_opts, prefix='randomize_other_'):
|
||||
if param in ['CLIP_stop_at_last_layers', 'eta_noise_seed_delta', 'use_scale_latent_for_hires_fix']:
|
||||
if param in ['CLIP_stop_at_last_layers', 'eta_noise_seed_delta']:
|
||||
opts.data[param] = self._opt({param: val}, p) # type: ignore
|
||||
|
||||
# Highres. fix params
|
||||
if len(randomize_hires.strip()) > 0:
|
||||
if len(randomize_hires_chance.strip()) > 0:
|
||||
fix_job_count = False
|
||||
if p.enable_hr:
|
||||
fix_job_count = True
|
||||
if random.random() < float(randomize_hires or 0):
|
||||
try:
|
||||
setattr(p, 'enable_hr', True)
|
||||
setattr(p, 'firstphase_width', 0)
|
||||
setattr(p, 'firstphase_height', 0)
|
||||
if random.random() < float(randomize_hires_chance or 0):
|
||||
setattr(p, 'enable_hr', True)
|
||||
|
||||
denoising_strength = self._opt({'denoising_strength': randomize_hires_denoising_strength}, p)
|
||||
if denoising_strength:
|
||||
setattr(p, 'denoising_strength', denoising_strength)
|
||||
else:
|
||||
# Default value used by WebUI
|
||||
setattr(p, 'denoising_strength', 0.7)
|
||||
if not p.denoising_strength:
|
||||
setattr(p, 'denoising_strength', 0.75)
|
||||
|
||||
hires_width = self._opt({'width': randomize_hires_width}, p)
|
||||
hires_height = self._opt({'height': randomize_hires_height}, p)
|
||||
if hires_width:
|
||||
setattr(p, 'width', hires_width)
|
||||
if hires_height:
|
||||
setattr(p, 'height', hires_height)
|
||||
for param, val in self._list_params(all_opts, prefix='randomize_hr_'):
|
||||
self._set_attr(p, param, val)
|
||||
|
||||
# Set up highres. fix related stuff by re-running init function
|
||||
p.init(p.all_prompts, p.all_seeds, p.all_subseeds)
|
||||
if fix_job_count:
|
||||
state.job_count = math.floor(state.job_count / 2)
|
||||
except (TypeError, IndexError) as exception:
|
||||
print(f'Failed to utilize highres. fix -- incorrect value?', exception)
|
||||
p.init(p.all_prompts, p.all_seeds, p.all_subseeds)
|
||||
if fix_job_count:
|
||||
state.job_count = math.floor(state.job_count / 2)
|
||||
else:
|
||||
setattr(p, 'enable_hr', False)
|
||||
p.init(p.all_prompts, p.all_seeds, p.all_subseeds)
|
||||
|
@ -179,9 +147,25 @@ class RandomizeScript(scripts.Script):
|
|||
|
||||
if hasattr(self, 'CLIP_stop_at_last_layers'):
|
||||
opts.data["CLIP_stop_at_last_layers"] = self.CLIP_stop_at_last_layers # type: ignore
|
||||
opts.data["use_scale_latent_for_hires_fix"] = self.use_scale_latent_for_hires_fix # type: ignore
|
||||
opts.data["eta_noise_seed_delta"] = self.eta_noise_seed_delta # type: ignore
|
||||
|
||||
def _set_attr(self, p, param, val):
|
||||
try:
|
||||
# Backwards compat
|
||||
if param == 'sampler_name' and hasattr(p, 'sampler_index') and not hasattr(p, 'sampler_name'):
|
||||
param = 'sampler_index'
|
||||
|
||||
opt = self._opt({param: val}, p)
|
||||
if opt is not None:
|
||||
if param in ['seed']:
|
||||
setattr(p, 'all_seeds', [self._opt({param: val}, p) for _ in range(0, len(getattr(p, 'all_seeds')))]) # NOTE (mmaker): Is this correct?
|
||||
else:
|
||||
setattr(p, param, opt)
|
||||
else:
|
||||
print(f'Skipping randomizing param `{param}` -- incorrect value')
|
||||
except (TypeError, IndexError) as exception:
|
||||
print(f'Failed to randomize param `{param}` -- incorrect value?', exception)
|
||||
|
||||
def _list_params(self, opts, prefix='randomize_param_'):
|
||||
for k, v in opts.items():
|
||||
if k.startswith(prefix) and v is not None and len(v) > 0:
|
||||
|
@ -193,7 +177,7 @@ class RandomizeScript(scripts.Script):
|
|||
|
||||
opt_arr: list[str] = [x.strip() for x in opt_val.split(',')]
|
||||
|
||||
if self._is_num(opt_arr[0]) and len(opt_arr) == 3 and opt_name not in ['seed', 'use_scale_latent_for_hires_fix']:
|
||||
if self._is_num(opt_arr[0]) and len(opt_arr) == 3 and opt_name not in ['seed']:
|
||||
vals = [float(v) for v in opt_arr]
|
||||
rand = self._rand(vals[0], vals[1], vals[2])
|
||||
if rand.is_integer():
|
||||
|
@ -231,10 +215,10 @@ class RandomizeScript(scripts.Script):
|
|||
if opt_val == '*':
|
||||
return [random.choice([k for k, v in shared.prompt_styles.styles.items() if k != 'None'])]
|
||||
return [random.choice(opt_arr)]
|
||||
if opt_name == 'use_scale_latent_for_hires_fix':
|
||||
if opt_name == 'hr_upscaler':
|
||||
if opt_val == '*':
|
||||
return random.choice([0,1])
|
||||
return int(random.choice(opt_arr))
|
||||
return random.choice([*shared.latent_upscale_modes, *[x.name for x in shared.sd_upscalers]])
|
||||
return random.choice(opt_arr)
|
||||
|
||||
return None
|
||||
|
||||
|
@ -279,11 +263,12 @@ class RandomizeScript(scripts.Script):
|
|||
randomize_param_steps = gr.Textbox(label='Steps', value='', placeholder=hint_minmax)
|
||||
randomize_param_width = gr.Textbox(label='Width', value='', placeholder=hint_minmax)
|
||||
randomize_param_height = gr.Textbox(label='Height', value='', placeholder=hint_minmax)
|
||||
randomize_hires = gr.Textbox(label='Highres. percentage chance', value='', placeholder=hint_float)
|
||||
randomize_hires_denoising_strength = gr.Textbox(label='Highres. Denoising Strength', value='', placeholder=hint_minmax)
|
||||
randomize_hires_width = gr.Textbox(label='Highres. Width', value='', placeholder=hint_minmax)
|
||||
randomize_hires_height = gr.Textbox(label='Highres. Height', value='', placeholder=hint_minmax)
|
||||
randomize_other_use_scale_latent_for_hires_fix = gr.Textbox(label='Upscale latent space for highres. fix', value='', placeholder=hint_list)
|
||||
|
||||
randomize_hires_chance = gr.Textbox(label='Highres. percentage chance', value='', placeholder=hint_float)
|
||||
randomize_hr_hr_upscaler = gr.Textbox(label='Highres. Upscaler', value='', placeholder=hint_list)
|
||||
randomize_hr_hr_scale = gr.Textbox(label='Highres. Upscale by', value='', placeholder=hint_minmax)
|
||||
randomize_hr_denoising_strength = gr.Textbox(label='Highres. Denoising Strength', value='', placeholder=hint_minmax)
|
||||
|
||||
randomize_other_CLIP_stop_at_last_layers = gr.Textbox(label='Stop at CLIP layers', value='', placeholder=hint_minmax)
|
||||
randomize_other_sd_model_checkpoint = gr.Textbox(label='Checkpoint name', value='', placeholder=hint_list)
|
||||
randomize_other_sd_hypernetwork = gr.Textbox(label='Hypernetwork', value='', placeholder=hint_list)
|
||||
|
@ -291,4 +276,4 @@ class RandomizeScript(scripts.Script):
|
|||
randomize_other_eta_noise_seed_delta = gr.Textbox(label='Eta noise seed delta', value='', placeholder=hint_minmax)
|
||||
randomize_other_styles = gr.Textbox(label='Styles', value='', placeholder=hint_list)
|
||||
|
||||
return randomize_enabled, randomize_param_sampler_name, randomize_param_cfg_scale, randomize_param_steps, randomize_param_width, randomize_param_height, randomize_hires, randomize_hires_denoising_strength, randomize_hires_width, randomize_hires_height, randomize_other_use_scale_latent_for_hires_fix, randomize_other_CLIP_stop_at_last_layers, randomize_other_sd_model_checkpoint, randomize_other_sd_hypernetwork, randomize_other_sd_hypernetwork_strength, randomize_other_eta_noise_seed_delta, randomize_other_styles
|
||||
return randomize_enabled, randomize_param_sampler_name, randomize_param_cfg_scale, randomize_param_steps, randomize_param_width, randomize_param_height, randomize_hires_chance, randomize_hr_hr_upscaler, randomize_hr_hr_scale, randomize_hr_denoising_strength, randomize_other_CLIP_stop_at_last_layers, randomize_other_sd_model_checkpoint, randomize_other_sd_hypernetwork, randomize_other_sd_hypernetwork_strength, randomize_other_eta_noise_seed_delta, randomize_other_styles
|
||||
|
|
Reference in New Issue