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
d641af6a
Commit
d641af6a
authored
Sep 28, 2022
by
Bernard Maltais
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- Add gradio dropdown list to select checkpoints
- Update checkpoint model fields labels
parent
591c138e
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
18 deletions
+19
-18
extras.py
modules/extras.py
+14
-14
ui.py
modules/ui.py
+5
-4
No files found.
modules/extras.py
View file @
d641af6a
...
@@ -140,7 +140,7 @@ def run_pnginfo(image):
...
@@ -140,7 +140,7 @@ def run_pnginfo(image):
return
''
,
geninfo
,
info
return
''
,
geninfo
,
info
def
run_modelmerger
(
from_model_name
,
to
_model_name
,
interp_method
,
interp_amount
):
def
run_modelmerger
(
primary_model_name
,
secondary
_model_name
,
interp_method
,
interp_amount
):
# Linear interpolation (https://en.wikipedia.org/wiki/Linear_interpolation)
# Linear interpolation (https://en.wikipedia.org/wiki/Linear_interpolation)
def
weighted_sum
(
theta0
,
theta1
,
alpha
):
def
weighted_sum
(
theta0
,
theta1
,
alpha
):
return
((
1
-
alpha
)
*
theta0
)
+
(
alpha
*
theta1
)
return
((
1
-
alpha
)
*
theta0
)
+
(
alpha
*
theta1
)
...
@@ -150,23 +150,23 @@ def run_modelmerger(from_model_name, to_model_name, interp_method, interp_amount
...
@@ -150,23 +150,23 @@ def run_modelmerger(from_model_name, to_model_name, interp_method, interp_amount
alpha
=
alpha
*
alpha
*
(
3
-
(
2
*
alpha
))
alpha
=
alpha
*
alpha
*
(
3
-
(
2
*
alpha
))
return
theta0
+
((
theta1
-
theta0
)
*
alpha
)
return
theta0
+
((
theta1
-
theta0
)
*
alpha
)
if
os
.
path
.
exists
(
to
_model_name
):
if
os
.
path
.
exists
(
secondary
_model_name
):
to_model_filename
=
to
_model_name
secondary_model_filename
=
secondary
_model_name
to_model_name
=
os
.
path
.
splitext
(
os
.
path
.
basename
(
to
_model_name
))[
0
]
secondary_model_name
=
os
.
path
.
splitext
(
os
.
path
.
basename
(
secondary
_model_name
))[
0
]
else
:
else
:
to_model_filename
=
'models/'
+
to
_model_name
+
'.ckpt'
secondary_model_filename
=
'models/'
+
secondary
_model_name
+
'.ckpt'
if
os
.
path
.
exists
(
from
_model_name
):
if
os
.
path
.
exists
(
primary
_model_name
):
from_model_filename
=
from
_model_name
primary_model_filename
=
primary
_model_name
from_model_name
=
os
.
path
.
splitext
(
os
.
path
.
basename
(
from
_model_name
))[
0
]
primary_model_name
=
os
.
path
.
splitext
(
os
.
path
.
basename
(
primary
_model_name
))[
0
]
else
:
else
:
from_model_filename
=
'models/'
+
from
_model_name
+
'.ckpt'
primary_model_filename
=
'models/'
+
primary
_model_name
+
'.ckpt'
print
(
f
"Loading {
to
_model_filename}..."
)
print
(
f
"Loading {
secondary
_model_filename}..."
)
model_0
=
torch
.
load
(
to
_model_filename
,
map_location
=
'cpu'
)
model_0
=
torch
.
load
(
secondary
_model_filename
,
map_location
=
'cpu'
)
print
(
f
"Loading {
from
_model_filename}..."
)
print
(
f
"Loading {
primary
_model_filename}..."
)
model_1
=
torch
.
load
(
from
_model_filename
,
map_location
=
'cpu'
)
model_1
=
torch
.
load
(
primary
_model_filename
,
map_location
=
'cpu'
)
theta_0
=
model_0
[
'state_dict'
]
theta_0
=
model_0
[
'state_dict'
]
theta_1
=
model_1
[
'state_dict'
]
theta_1
=
model_1
[
'state_dict'
]
...
@@ -186,7 +186,7 @@ def run_modelmerger(from_model_name, to_model_name, interp_method, interp_amount
...
@@ -186,7 +186,7 @@ def run_modelmerger(from_model_name, to_model_name, interp_method, interp_amount
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/'
+
from_model_name
+
'_'
+
str
(
interp_amount
)
+
'-'
+
to
_model_name
+
'_'
+
str
(
float
(
1.0
)
-
interp_amount
)
+
'-'
+
interp_method
.
replace
(
" "
,
"_"
)
+
'-merged.ckpt'
output_modelname
=
'models/'
+
primary_model_name
+
'_'
+
str
(
interp_amount
)
+
'-'
+
secondary
_model_name
+
'_'
+
str
(
float
(
1.0
)
-
interp_amount
)
+
'-'
+
interp_method
.
replace
(
" "
,
"_"
)
+
'-merged.ckpt'
print
(
f
"Saving to {output_modelname}..."
)
print
(
f
"Saving to {output_modelname}..."
)
torch
.
save
(
model_0
,
output_modelname
)
torch
.
save
(
model_0
,
output_modelname
)
...
...
modules/ui.py
View file @
d641af6a
...
@@ -860,8 +860,9 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo, run_modelmerger):
...
@@ -860,8 +860,9 @@ 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
():
from_model_name
=
gr
.
Textbox
(
elem_id
=
"modelmerger_from_model_name"
,
label
=
"Model Name (from)"
)
ckpt_name_list
=
[
x
.
model_name
for
x
in
modules
.
sd_models
.
checkpoints_list
.
values
()]
to_model_name
=
gr
.
Textbox
(
elem_id
=
"modelmerger_to_model_name"
,
label
=
"Model Name (to)"
)
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"
)
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"
],
value
=
"Weighted Sum"
,
label
=
"Interpolation Method"
)
interp_method
=
gr
.
Radio
(
choices
=
[
"Weighted Sum"
,
"Sigmoid"
],
value
=
"Weighted Sum"
,
label
=
"Interpolation Method"
)
submit
=
gr
.
Button
(
elem_id
=
"modelmerger_merge"
,
label
=
"Merge"
,
variant
=
'primary'
)
submit
=
gr
.
Button
(
elem_id
=
"modelmerger_merge"
,
label
=
"Merge"
,
variant
=
'primary'
)
...
@@ -872,8 +873,8 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo, run_modelmerger):
...
@@ -872,8 +873,8 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo, run_modelmerger):
submit
.
click
(
submit
.
click
(
fn
=
run_modelmerger
,
fn
=
run_modelmerger
,
inputs
=
[
inputs
=
[
from
_model_name
,
primary
_model_name
,
to
_model_name
,
secondary
_model_name
,
interp_method
,
interp_method
,
interp_amount
interp_amount
],
],
...
...
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