Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
S
stable-diffusion-webui
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
stable-diffusion-webui
Commits
791808c8
Commit
791808c8
authored
Sep 28, 2022
by
AUTOMATIC
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
correctly list and display model names for #1261
parent
43e27300
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
17 deletions
+10
-17
extras.py
modules/extras.py
+8
-15
ui.py
modules/ui.py
+2
-2
No files found.
modules/extras.py
View file @
791808c8
...
@@ -6,7 +6,7 @@ from PIL import Image
...
@@ -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
...
@@ -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
...
@@ -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,9 +184,11 @@ def run_modelmerger(primary_model_name, secondary_model_name, interp_method, int
...
@@ -193,9 +184,11 @@ 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
)
print
(
f
"Checkpoint saved."
)
print
(
f
"Checkpoint saved."
)
return
"Checkpoint saved to "
+
output_modelname
return
"Checkpoint saved to "
+
output_modelname
\ No newline at end of file
modules/ui.py
View file @
791808c8
...
@@ -872,8 +872,8 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo, run_modelmerger):
...
@@ -872,8 +872,8 @@ 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_nam
e
for
x
in
modules
.
sd_models
.
checkpoints_list
.
values
()])
ckpt_name_list
=
sorted
([
x
.
titl
e
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
)
interp_method
=
gr
.
Radio
(
choices
=
[
"Weighted Sum"
,
"Sigmoid"
,
"Inverse Sigmoid"
],
value
=
"Weighted Sum"
,
label
=
"Interpolation Method"
)
interp_method
=
gr
.
Radio
(
choices
=
[
"Weighted Sum"
,
"Sigmoid"
,
"Inverse Sigmoid"
],
value
=
"Weighted Sum"
,
label
=
"Interpolation Method"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment