Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
Stable Diffusion Webui
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
novelai-storage
Stable Diffusion Webui
Commits
7c9c19b2
Commit
7c9c19b2
authored
Aug 11, 2023
by
catboxanon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor postprocessing to use generator to resolve OOM issues
parent
ae6b3090
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
32 deletions
+31
-32
modules/postprocessing.py
modules/postprocessing.py
+31
-32
No files found.
modules/postprocessing.py
View file @
7c9c19b2
...
...
@@ -11,37 +11,32 @@ def run_postprocessing(extras_mode, image, image_folder, input_dir, output_dir,
shared
.
state
.
begin
(
job
=
"extras"
)
image_data
=
[]
image_names
=
[]
outputs
=
[]
if
extras_mode
==
1
:
for
img
in
image_folder
:
if
isinstance
(
img
,
Image
.
Image
):
image
=
img
fn
=
''
else
:
image
=
Image
.
open
(
os
.
path
.
abspath
(
img
.
name
))
fn
=
os
.
path
.
splitext
(
img
.
orig_name
)[
0
]
image_data
.
append
(
image
)
image_names
.
append
(
fn
)
elif
extras_mode
==
2
:
assert
not
shared
.
cmd_opts
.
hide_ui_dir_config
,
'--hide-ui-dir-config option must be disabled'
assert
input_dir
,
'input directory not selected'
image_list
=
shared
.
listfiles
(
input_dir
)
for
filename
in
image_list
:
try
:
image
=
Image
.
open
(
filename
)
except
Exception
:
continue
image_data
.
append
(
image
)
image_names
.
append
(
filename
)
else
:
assert
image
,
'image not selected'
image_data
.
append
(
image
)
image_names
.
append
(
None
)
def
get_images
(
extras_mode
,
image
,
image_folder
,
input_dir
):
if
extras_mode
==
1
:
for
img
in
image_folder
:
if
isinstance
(
img
,
Image
.
Image
):
image
=
img
fn
=
''
else
:
image
=
Image
.
open
(
os
.
path
.
abspath
(
img
.
name
))
fn
=
os
.
path
.
splitext
(
img
.
orig_name
)[
0
]
yield
image
,
fn
elif
extras_mode
==
2
:
assert
not
shared
.
cmd_opts
.
hide_ui_dir_config
,
'--hide-ui-dir-config option must be disabled'
assert
input_dir
,
'input directory not selected'
image_list
=
shared
.
listfiles
(
input_dir
)
for
filename
in
image_list
:
try
:
image
=
Image
.
open
(
filename
)
except
Exception
:
continue
yield
image
,
filename
else
:
assert
image
,
'image not selected'
yield
image
,
None
if
extras_mode
==
2
and
output_dir
!=
''
:
outpath
=
output_dir
...
...
@@ -50,14 +45,16 @@ def run_postprocessing(extras_mode, image, image_folder, input_dir, output_dir,
infotext
=
''
for
image
,
name
in
zip
(
image_data
,
image_names
):
for
image_data
,
name
in
get_images
(
extras_mode
,
image
,
image_folder
,
input_dir
):
image_data
:
Image
.
Image
shared
.
state
.
textinfo
=
name
parameters
,
existing_pnginfo
=
images
.
read_info_from_image
(
image
)
parameters
,
existing_pnginfo
=
images
.
read_info_from_image
(
image
_data
)
if
parameters
:
existing_pnginfo
[
"parameters"
]
=
parameters
pp
=
scripts_postprocessing
.
PostprocessedImage
(
image
.
convert
(
"RGB"
))
pp
=
scripts_postprocessing
.
PostprocessedImage
(
image
_data
.
convert
(
"RGB"
))
scripts
.
scripts_postproc
.
run
(
pp
,
args
)
...
...
@@ -78,6 +75,8 @@ def run_postprocessing(extras_mode, image, image_folder, input_dir, output_dir,
if
extras_mode
!=
2
or
show_extras_results
:
outputs
.
append
(
pp
.
image
)
image_data
.
close
()
devices
.
torch_gc
()
return
outputs
,
ui_common
.
plaintext_to_html
(
infotext
),
''
...
...
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