correctly list and display model names for #1261
This commit is contained in:
parent
43e273004b
commit
791808c890
2 changed files with 10 additions and 17 deletions
|
@ -6,7 +6,7 @@ from PIL import Image
|
||||||
import torch
|
import torch
|
||||||
import tqdm
|
import tqdm
|
||||||
|
|
||||||
from modules import processing, shared, images, devices
|
from modules import processing, shared, images, devices, sd_models
|
||||||
from modules.shared import opts
|
from modules.shared import opts
|
||||||
import modules.gfpgan_model
|
import modules.gfpgan_model
|
||||||
from modules.ui import plaintext_to_html
|
from modules.ui import plaintext_to_html
|
||||||
|
@ -156,17 +156,8 @@ def run_modelmerger(primary_model_name, secondary_model_name, interp_method, int
|
||||||
alpha = 0.5 - math.sin(math.asin(1.0 - 2.0 * alpha) / 3.0)
|
alpha = 0.5 - math.sin(math.asin(1.0 - 2.0 * alpha) / 3.0)
|
||||||
return theta0 + ((theta1 - theta0) * alpha)
|
return theta0 + ((theta1 - theta0) * alpha)
|
||||||
|
|
||||||
if os.path.exists(primary_model_name):
|
primary_model_filename = sd_models.checkpoints_list[primary_model_name].filename
|
||||||
primary_model_filename = primary_model_name
|
secondary_model_filename = sd_models.checkpoints_list[secondary_model_name].filename
|
||||||
primary_model_name = os.path.splitext(os.path.basename(primary_model_name))[0]
|
|
||||||
else:
|
|
||||||
primary_model_filename = 'models/' + primary_model_name + '.ckpt'
|
|
||||||
|
|
||||||
if os.path.exists(secondary_model_name):
|
|
||||||
secondary_model_filename = secondary_model_name
|
|
||||||
secondary_model_name = os.path.splitext(os.path.basename(secondary_model_name))[0]
|
|
||||||
else:
|
|
||||||
secondary_model_filename = 'models/' + secondary_model_name + '.ckpt'
|
|
||||||
|
|
||||||
print(f"Loading {primary_model_filename}...")
|
print(f"Loading {primary_model_filename}...")
|
||||||
primary_model = torch.load(primary_model_filename, map_location='cpu')
|
primary_model = torch.load(primary_model_filename, map_location='cpu')
|
||||||
|
@ -180,7 +171,7 @@ def run_modelmerger(primary_model_name, secondary_model_name, interp_method, int
|
||||||
theta_funcs = {
|
theta_funcs = {
|
||||||
"Weighted Sum": weighted_sum,
|
"Weighted Sum": weighted_sum,
|
||||||
"Sigmoid": sigmoid,
|
"Sigmoid": sigmoid,
|
||||||
"Inverse Sigmoid": inv_sigmoid
|
"Inverse Sigmoid": inv_sigmoid,
|
||||||
}
|
}
|
||||||
theta_func = theta_funcs[interp_method]
|
theta_func = theta_funcs[interp_method]
|
||||||
|
|
||||||
|
@ -193,7 +184,9 @@ def run_modelmerger(primary_model_name, secondary_model_name, interp_method, int
|
||||||
if 'model' in key and key not in theta_0:
|
if 'model' in key and key not in theta_0:
|
||||||
theta_0[key] = theta_1[key]
|
theta_0[key] = theta_1[key]
|
||||||
|
|
||||||
output_modelname = 'models/' + primary_model_name + '_' + str(round(interp_amount,2)) + '-' + secondary_model_name + '_' + str(round((float(1.0) - interp_amount),2)) + '-' + interp_method.replace(" ", "_") + '-merged.ckpt'
|
filename = primary_model_name + '_' + str(round(interp_amount,2)) + '-' + secondary_model_name + '_' + str(round((float(1.0) - interp_amount),2)) + '-' + interp_method.replace(" ", "_") + '-merged.ckpt'
|
||||||
|
output_modelname = os.path.join(shared.cmd_opts.ckpt_dir, filename)
|
||||||
|
|
||||||
print(f"Saving to {output_modelname}...")
|
print(f"Saving to {output_modelname}...")
|
||||||
torch.save(primary_model, output_modelname)
|
torch.save(primary_model, output_modelname)
|
||||||
|
|
||||||
|
|
|
@ -872,7 +872,7 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo, run_modelmerger):
|
||||||
gr.HTML(value="<p>A merger of the two checkpoints will be generated in your <b>/models</b> directory.</p>")
|
gr.HTML(value="<p>A merger of the two checkpoints will be generated in your <b>/models</b> directory.</p>")
|
||||||
|
|
||||||
with gr.Row():
|
with gr.Row():
|
||||||
ckpt_name_list = sorted([x.model_name for x in modules.sd_models.checkpoints_list.values()])
|
ckpt_name_list = sorted([x.title for x in modules.sd_models.checkpoints_list.values()])
|
||||||
primary_model_name = gr.Dropdown(ckpt_name_list, elem_id="modelmerger_primary_model_name", label="Primary Model Name")
|
primary_model_name = gr.Dropdown(ckpt_name_list, elem_id="modelmerger_primary_model_name", label="Primary Model Name")
|
||||||
secondary_model_name = gr.Dropdown(ckpt_name_list, elem_id="modelmerger_secondary_model_name", label="Secondary Model Name")
|
secondary_model_name = gr.Dropdown(ckpt_name_list, elem_id="modelmerger_secondary_model_name", label="Secondary Model Name")
|
||||||
interp_amount = gr.Slider(minimum=0.0, maximum=1.0, step=0.05, label='Interpolation Amount', value=0.3)
|
interp_amount = gr.Slider(minimum=0.0, maximum=1.0, step=0.05, label='Interpolation Amount', value=0.3)
|
||||||
|
|
Loading…
Reference in a new issue