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
91efe138
Unverified
Commit
91efe138
authored
Oct 20, 2022
by
wywywywy
Committed by
GitHub
Oct 20, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented batch_size logic in outpainting_mk2
parent
4281f255
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
55 deletions
+63
-55
outpainting_mk_2.py
scripts/outpainting_mk_2.py
+63
-55
No files found.
scripts/outpainting_mk_2.py
View file @
91efe138
...
@@ -176,50 +176,53 @@ class Script(scripts.Script):
...
@@ -176,50 +176,53 @@ class Script(scripts.Script):
state
.
job_count
=
(
1
if
left
>
0
else
0
)
+
(
1
if
right
>
0
else
0
)
+
(
1
if
up
>
0
else
0
)
+
(
1
if
down
>
0
else
0
)
state
.
job_count
=
(
1
if
left
>
0
else
0
)
+
(
1
if
right
>
0
else
0
)
+
(
1
if
up
>
0
else
0
)
+
(
1
if
down
>
0
else
0
)
def
expand
(
init
,
expand_pixels
,
is_left
=
False
,
is_right
=
False
,
is_top
=
False
,
is_bottom
=
False
):
def
expand
(
init
,
count
,
expand_pixels
,
is_left
=
False
,
is_right
=
False
,
is_top
=
False
,
is_bottom
=
False
):
is_horiz
=
is_left
or
is_right
is_horiz
=
is_left
or
is_right
is_vert
=
is_top
or
is_bottom
is_vert
=
is_top
or
is_bottom
pixels_horiz
=
expand_pixels
if
is_horiz
else
0
pixels_horiz
=
expand_pixels
if
is_horiz
else
0
pixels_vert
=
expand_pixels
if
is_vert
else
0
pixels_vert
=
expand_pixels
if
is_vert
else
0
res_w
=
init
.
width
+
pixels_horiz
images_to_process
=
[]
res_h
=
init
.
height
+
pixels_vert
for
n
in
range
(
count
):
process_res_w
=
math
.
ceil
(
res_w
/
64
)
*
64
res_w
=
init
[
n
]
.
width
+
pixels_horiz
process_res_h
=
math
.
ceil
(
res_h
/
64
)
*
64
res_h
=
init
[
n
]
.
height
+
pixels_vert
process_res_w
=
math
.
ceil
(
res_w
/
64
)
*
64
img
=
Image
.
new
(
"RGB"
,
(
process_res_w
,
process_res_h
))
process_res_h
=
math
.
ceil
(
res_h
/
64
)
*
64
img
.
paste
(
init
,
(
pixels_horiz
if
is_left
else
0
,
pixels_vert
if
is_top
else
0
))
mask
=
Image
.
new
(
"RGB"
,
(
process_res_w
,
process_res_h
),
"white"
)
img
=
Image
.
new
(
"RGB"
,
(
process_res_w
,
process_res_h
))
draw
=
ImageDraw
.
Draw
(
mask
)
img
.
paste
(
init
[
n
],
(
pixels_horiz
if
is_left
else
0
,
pixels_vert
if
is_top
else
0
))
draw
.
rectangle
((
mask
=
Image
.
new
(
"RGB"
,
(
process_res_w
,
process_res_h
),
"white"
)
expand_pixels
+
mask_blur
if
is_left
else
0
,
draw
=
ImageDraw
.
Draw
(
mask
)
expand_pixels
+
mask_blur
if
is_top
else
0
,
draw
.
rectangle
((
mask
.
width
-
expand_pixels
-
mask_blur
if
is_right
else
res_w
,
expand_pixels
+
mask_blur
if
is_left
else
0
,
mask
.
height
-
expand_pixels
-
mask_blur
if
is_bottom
else
res_h
,
expand_pixels
+
mask_blur
if
is_top
else
0
,
),
fill
=
"black"
)
mask
.
width
-
expand_pixels
-
mask_blur
if
is_right
else
res_w
,
mask
.
height
-
expand_pixels
-
mask_blur
if
is_bottom
else
res_h
,
np_image
=
(
np
.
asarray
(
img
)
/
255.0
)
.
astype
(
np
.
float64
)
),
fill
=
"black"
)
np_mask
=
(
np
.
asarray
(
mask
)
/
255.0
)
.
astype
(
np
.
float64
)
noised
=
get_matched_noise
(
np_image
,
np_mask
,
noise_q
,
color_variation
)
np_image
=
(
np
.
asarray
(
img
)
/
255.0
)
.
astype
(
np
.
float64
)
out
=
Image
.
fromarray
(
np
.
clip
(
noised
*
255.
,
0.
,
255.
)
.
astype
(
np
.
uint8
),
mode
=
"RGB"
)
np_mask
=
(
np
.
asarray
(
mask
)
/
255.0
)
.
astype
(
np
.
float64
)
noised
=
get_matched_noise
(
np_image
,
np_mask
,
noise_q
,
color_variation
)
target_width
=
min
(
process_width
,
init
.
width
+
pixels_horiz
)
if
is_horiz
else
img
.
width
out
=
Image
.
fromarray
(
np
.
clip
(
noised
*
255.
,
0.
,
255.
)
.
astype
(
np
.
uint8
),
mode
=
"RGB"
)
target_height
=
min
(
process_height
,
init
.
height
+
pixels_vert
)
if
is_vert
else
img
.
height
target_width
=
min
(
process_width
,
init
[
n
]
.
width
+
pixels_horiz
)
if
is_horiz
else
img
.
width
crop_region
=
(
target_height
=
min
(
process_height
,
init
[
n
]
.
height
+
pixels_vert
)
if
is_vert
else
img
.
height
0
if
is_left
else
out
.
width
-
target_width
,
p
.
width
=
target_width
if
is_horiz
else
img
.
width
0
if
is_top
else
out
.
height
-
target_height
,
p
.
height
=
target_height
if
is_vert
else
img
.
height
target_width
if
is_left
else
out
.
width
,
target_height
if
is_top
else
out
.
height
,
crop_region
=
(
)
0
if
is_left
else
out
.
width
-
target_width
,
0
if
is_top
else
out
.
height
-
target_height
,
image_to_process
=
out
.
crop
(
crop_region
)
target_width
if
is_left
else
out
.
width
,
mask
=
mask
.
crop
(
crop_region
)
target_height
if
is_top
else
out
.
height
,
)
p
.
width
=
target_width
if
is_horiz
else
img
.
width
mask
=
mask
.
crop
(
crop_region
)
p
.
height
=
target_height
if
is_vert
else
img
.
height
p
.
image_mask
=
mask
p
.
init_images
=
[
image_to_process
]
p
.
image_mask
=
mask
image_to_process
=
out
.
crop
(
crop_region
)
images_to_process
.
append
(
image_to_process
)
p
.
init_images
=
images_to_process
latent_mask
=
Image
.
new
(
"RGB"
,
(
p
.
width
,
p
.
height
),
"white"
)
latent_mask
=
Image
.
new
(
"RGB"
,
(
p
.
width
,
p
.
height
),
"white"
)
draw
=
ImageDraw
.
Draw
(
latent_mask
)
draw
=
ImageDraw
.
Draw
(
latent_mask
)
...
@@ -232,44 +235,49 @@ class Script(scripts.Script):
...
@@ -232,44 +235,49 @@ class Script(scripts.Script):
p
.
latent_mask
=
latent_mask
p
.
latent_mask
=
latent_mask
proc
=
process_images
(
p
)
proc
=
process_images
(
p
)
proc_img
=
proc
.
images
[
0
]
if
initial_seed_and_info
[
0
]
is
None
:
if
initial_seed_and_info
[
0
]
is
None
:
initial_seed_and_info
[
0
]
=
proc
.
seed
initial_seed_and_info
[
0
]
=
proc
.
seed
initial_seed_and_info
[
1
]
=
proc
.
info
initial_seed_and_info
[
1
]
=
proc
.
info
out
.
paste
(
proc_img
,
(
0
if
is_left
else
out
.
width
-
proc_img
.
width
,
0
if
is_top
else
out
.
height
-
proc_img
.
height
))
for
proc_img
in
proc
.
images
:
out
=
out
.
crop
((
0
,
0
,
res_w
,
res_h
))
out
.
paste
(
proc_img
,
(
0
if
is_left
else
out
.
width
-
proc_img
.
width
,
0
if
is_top
else
out
.
height
-
proc_img
.
height
))
return
out
out
=
out
.
crop
((
0
,
0
,
res_w
,
res_h
))
return
proc
.
images
batch_count
=
p
.
n_iter
batch_count
=
p
.
n_iter
batch_size
=
p
.
batch_size
p
.
n_iter
=
1
p
.
n_iter
=
1
state
.
job_count
=
batch_count
state
.
job_count
=
batch_count
all_images
=
[]
all_
processed_
images
=
[]
for
i
in
range
(
batch_count
):
for
i
in
range
(
batch_count
):
img
=
init_imag
e
img
s
=
[
init_img
]
*
batch_siz
e
state
.
job
=
f
"Batch {i + 1} out of {
state.job
_count}"
state
.
job
=
f
"Batch {i + 1} out of {
batch
_count}"
if
left
>
0
:
if
left
>
0
:
img
=
expand
(
img
,
left
,
is_left
=
True
)
img
s
=
expand
(
imgs
,
batch_size
,
left
,
is_left
=
True
)
if
right
>
0
:
if
right
>
0
:
img
=
expand
(
img
,
right
,
is_right
=
True
)
img
s
=
expand
(
imgs
,
batch_size
,
right
,
is_right
=
True
)
if
up
>
0
:
if
up
>
0
:
img
=
expand
(
img
,
up
,
is_top
=
True
)
img
s
=
expand
(
imgs
,
batch_size
,
up
,
is_top
=
True
)
if
down
>
0
:
if
down
>
0
:
img
=
expand
(
img
,
down
,
is_bottom
=
True
)
img
s
=
expand
(
imgs
,
batch_size
,
down
,
is_bottom
=
True
)
all_images
.
append
(
img
)
all_processed_images
+=
imgs
combined_grid_image
=
images
.
image_grid
(
all_processed_images
)
all_images
=
all_processed_images
combined_grid_image
=
images
.
image_grid
(
all_images
)
if
opts
.
return_grid
:
if
opts
.
return_grid
:
all_images
=
[
combined_grid_image
]
+
all_images
all_images
=
[
combined_grid_image
]
+
all_
processed_
images
res
=
Processed
(
p
,
all_images
,
initial_seed_and_info
[
0
],
initial_seed_and_info
[
1
])
res
=
Processed
(
p
,
all_images
,
initial_seed_and_info
[
0
],
initial_seed_and_info
[
1
])
if
opts
.
samples_save
:
if
opts
.
samples_save
:
images
.
save_image
(
img
,
p
.
outpath_samples
,
""
,
res
.
seed
,
p
.
prompt
,
opts
.
grid_format
,
info
=
res
.
info
,
p
=
p
)
for
img
in
all_processed_images
:
images
.
save_image
(
img
,
p
.
outpath_samples
,
""
,
res
.
seed
,
p
.
prompt
,
opts
.
grid_format
,
info
=
res
.
info
,
p
=
p
)
if
opts
.
grid_save
:
if
opts
.
grid_save
:
images
.
save_image
(
combined_grid_image
,
p
.
outpath_grids
,
"grid"
,
res
.
seed
,
p
.
prompt
,
opts
.
grid_format
,
info
=
res
.
info
,
short_filename
=
not
opts
.
grid_extended_filename
,
grid
=
True
,
p
=
p
)
images
.
save_image
(
combined_grid_image
,
p
.
outpath_grids
,
"grid"
,
res
.
seed
,
p
.
prompt
,
opts
.
grid_format
,
info
=
res
.
info
,
short_filename
=
not
opts
.
grid_extended_filename
,
grid
=
True
,
p
=
p
)
...
...
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