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
ec877472
Commit
ec877472
authored
Jan 24, 2023
by
EllangoK
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
swaps xyz axes internally if one costs more
parent
e46bfa5a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
12 deletions
+52
-12
xyz_grid.py
scripts/xyz_grid.py
+52
-12
No files found.
scripts/xyz_grid.py
View file @
ec877472
...
@@ -205,7 +205,7 @@ axis_options = [
...
@@ -205,7 +205,7 @@ axis_options = [
]
]
def
draw_xyz_grid
(
p
,
xs
,
ys
,
zs
,
x_labels
,
y_labels
,
z_labels
,
cell
,
draw_legend
,
include_lone_images
,
include_sub_grids
,
swap_axes_processing_order
):
def
draw_xyz_grid
(
p
,
xs
,
ys
,
zs
,
x_labels
,
y_labels
,
z_labels
,
cell
,
draw_legend
,
include_lone_images
,
include_sub_grids
,
first_axes_processed
,
second_axes_processed
):
hor_texts
=
[[
images
.
GridAnnotation
(
x
)]
for
x
in
x_labels
]
hor_texts
=
[[
images
.
GridAnnotation
(
x
)]
for
x
in
x_labels
]
ver_texts
=
[[
images
.
GridAnnotation
(
y
)]
for
y
in
y_labels
]
ver_texts
=
[[
images
.
GridAnnotation
(
y
)]
for
y
in
y_labels
]
title_texts
=
[[
images
.
GridAnnotation
(
z
)]
for
z
in
z_labels
]
title_texts
=
[[
images
.
GridAnnotation
(
z
)]
for
z
in
z_labels
]
...
@@ -224,7 +224,7 @@ def draw_xyz_grid(p, xs, ys, zs, x_labels, y_labels, z_labels, cell, draw_legend
...
@@ -224,7 +224,7 @@ def draw_xyz_grid(p, xs, ys, zs, x_labels, y_labels, z_labels, cell, draw_legend
nonlocal
image_cache
,
processed_result
,
cell_mode
,
cell_size
nonlocal
image_cache
,
processed_result
,
cell_mode
,
cell_size
def
index
(
ix
,
iy
,
iz
):
def
index
(
ix
,
iy
,
iz
):
return
ix
+
iy
*
len
(
xs
)
+
iz
*
len
(
xs
)
*
len
(
ys
)
return
ix
+
iy
*
len
(
xs
)
+
iz
*
len
(
xs
)
*
len
(
ys
)
state
.
job
=
f
"{index(ix, iy, iz) + 1} out of {len(xs) * len(ys) * len(zs)}"
state
.
job
=
f
"{index(ix, iy, iz) + 1} out of {len(xs) * len(ys) * len(zs)}"
...
@@ -251,16 +251,36 @@ def draw_xyz_grid(p, xs, ys, zs, x_labels, y_labels, z_labels, cell, draw_legend
...
@@ -251,16 +251,36 @@ def draw_xyz_grid(p, xs, ys, zs, x_labels, y_labels, z_labels, cell, draw_legend
except
:
except
:
image_cache
[
index
(
ix
,
iy
,
iz
)]
=
Image
.
new
(
cell_mode
,
cell_size
)
image_cache
[
index
(
ix
,
iy
,
iz
)]
=
Image
.
new
(
cell_mode
,
cell_size
)
if
swap_axes_processing_order
:
if
first_axes_processed
==
'x'
:
for
ix
,
x
in
enumerate
(
xs
):
for
ix
,
x
in
enumerate
(
xs
):
for
iy
,
y
in
enumerate
(
ys
):
if
second_axes_processed
==
'y'
:
for
iy
,
y
in
enumerate
(
zs
):
for
iy
,
y
in
enumerate
(
ys
):
process_cell
(
x
,
y
,
z
,
ix
,
iy
,
iz
)
for
iz
,
z
in
enumerate
(
zs
):
else
:
process_cell
(
x
,
y
,
z
,
ix
,
iy
,
iz
)
else
:
for
iz
,
z
in
enumerate
(
zs
):
for
iy
,
y
in
enumerate
(
ys
):
process_cell
(
x
,
y
,
z
,
ix
,
iy
,
iz
)
elif
first_axes_processed
==
'y'
:
for
iy
,
y
in
enumerate
(
ys
):
for
iy
,
y
in
enumerate
(
ys
):
for
ix
,
x
in
enumerate
(
xs
):
if
second_axes_processed
==
'x'
:
for
ix
,
x
in
enumerate
(
xs
):
for
iz
,
z
in
enumerate
(
zs
):
process_cell
(
x
,
y
,
z
,
ix
,
iy
,
iz
)
else
:
for
iz
,
z
in
enumerate
(
zs
):
for
iz
,
z
in
enumerate
(
zs
):
process_cell
(
x
,
y
,
z
,
ix
,
iy
,
iz
)
for
ix
,
x
in
enumerate
(
xs
):
process_cell
(
x
,
y
,
z
,
ix
,
iy
,
iz
)
elif
first_axes_processed
==
'z'
:
for
iz
,
z
in
enumerate
(
zs
):
if
second_axes_processed
==
'x'
:
for
ix
,
x
in
enumerate
(
xs
):
for
iy
,
y
in
enumerate
(
ys
):
process_cell
(
x
,
y
,
z
,
ix
,
iy
,
iz
)
else
:
for
iy
,
y
in
enumerate
(
ys
):
for
ix
,
x
in
enumerate
(
xs
):
process_cell
(
x
,
y
,
z
,
ix
,
iy
,
iz
)
if
not
processed_result
:
if
not
processed_result
:
print
(
"Unexpected error: draw_xyz_grid failed to return even a single processed image"
)
print
(
"Unexpected error: draw_xyz_grid failed to return even a single processed image"
)
...
@@ -322,7 +342,7 @@ class Script(scripts.Script):
...
@@ -322,7 +342,7 @@ class Script(scripts.Script):
with
gr
.
Row
():
with
gr
.
Row
():
y_type
=
gr
.
Dropdown
(
label
=
"Y type"
,
choices
=
[
x
.
label
for
x
in
self
.
current_axis_options
],
value
=
self
.
current_axis_options
[
0
]
.
label
,
type
=
"index"
,
elem_id
=
self
.
elem_id
(
"y_type"
))
y_type
=
gr
.
Dropdown
(
label
=
"Y type"
,
choices
=
[
x
.
label
for
x
in
self
.
current_axis_options
],
value
=
self
.
current_axis_options
[
0
]
.
label
,
type
=
"index"
,
elem_id
=
self
.
elem_id
(
"y_type"
))
y_values
=
gr
.
Textbox
(
label
=
"Y values"
,
lines
=
1
,
elem_id
=
self
.
elem_id
(
"y_values"
))
y_values
=
gr
.
Textbox
(
label
=
"Y values"
,
lines
=
1
,
elem_id
=
self
.
elem_id
(
"y_values"
))
fill_y_button
=
ToolButton
(
value
=
fill_values_symbol
,
elem_id
=
"xyz
z
_grid_fill_y_tool_button"
,
visible
=
False
)
fill_y_button
=
ToolButton
(
value
=
fill_values_symbol
,
elem_id
=
"xyz_grid_fill_y_tool_button"
,
visible
=
False
)
with
gr
.
Row
():
with
gr
.
Row
():
z_type
=
gr
.
Dropdown
(
label
=
"Z type"
,
choices
=
[
x
.
label
for
x
in
self
.
current_axis_options
],
value
=
self
.
current_axis_options
[
0
]
.
label
,
type
=
"index"
,
elem_id
=
self
.
elem_id
(
"z_type"
))
z_type
=
gr
.
Dropdown
(
label
=
"Z type"
,
choices
=
[
x
.
label
for
x
in
self
.
current_axis_options
],
value
=
self
.
current_axis_options
[
0
]
.
label
,
type
=
"index"
,
elem_id
=
self
.
elem_id
(
"z_type"
))
...
@@ -487,7 +507,26 @@ class Script(scripts.Script):
...
@@ -487,7 +507,26 @@ class Script(scripts.Script):
# If one of the axes is very slow to change between (like SD model
# If one of the axes is very slow to change between (like SD model
# checkpoint), then make sure it is in the outer iteration of the nested
# checkpoint), then make sure it is in the outer iteration of the nested
# `for` loop.
# `for` loop.
swap_axes_processing_order
=
x_opt
.
cost
>
y_opt
.
cost
first_axes_processed
=
'x'
second_axes_processed
=
'y'
if
x_opt
.
cost
>
y_opt
.
cost
and
x_opt
.
cost
>
z_opt
.
cost
:
first_axes_processed
=
'x'
if
y_opt
.
cost
>
z_opt
.
cost
:
second_axes_processed
=
'y'
else
:
second_axes_processed
=
'z'
elif
y_opt
.
cost
>
x_opt
.
cost
and
y_opt
.
cost
>
z_opt
.
cost
:
first_axes_processed
=
'y'
if
x_opt
.
cost
>
z_opt
.
cost
:
second_axes_processed
=
'x'
else
:
second_axes_processed
=
'z'
elif
z_opt
.
cost
>
x_opt
.
cost
and
z_opt
.
cost
>
y_opt
.
cost
:
first_axes_processed
=
'z'
if
x_opt
.
cost
>
y_opt
.
cost
:
second_axes_processed
=
'x'
else
:
second_axes_processed
=
'y'
def
cell
(
x
,
y
,
z
):
def
cell
(
x
,
y
,
z
):
if
shared
.
state
.
interrupted
:
if
shared
.
state
.
interrupted
:
...
@@ -538,7 +577,8 @@ class Script(scripts.Script):
...
@@ -538,7 +577,8 @@ class Script(scripts.Script):
draw_legend
=
draw_legend
,
draw_legend
=
draw_legend
,
include_lone_images
=
include_lone_images
,
include_lone_images
=
include_lone_images
,
include_sub_grids
=
include_sub_grids
,
include_sub_grids
=
include_sub_grids
,
swap_axes_processing_order
=
swap_axes_processing_order
first_axes_processed
=
first_axes_processed
,
second_axes_processed
=
second_axes_processed
)
)
if
opts
.
grid_save
:
if
opts
.
grid_save
:
...
...
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