@@ -11,37 +11,32 @@ def run_postprocessing(extras_mode, image, image_folder, input_dir, output_dir,
11
11
12
12
shared .state .begin (job = "extras" )
13
13
14
- image_data = []
15
- image_names = []
16
14
outputs = []
17
15
18
- if extras_mode == 1 :
19
- for img in image_folder :
20
- if isinstance (img , Image .Image ):
21
- image = img
22
- fn = ''
23
- else :
24
- image = Image .open (os .path .abspath (img .name ))
25
- fn = os .path .splitext (img .orig_name )[0 ]
26
- image_data .append (image )
27
- image_names .append (fn )
28
- elif extras_mode == 2 :
29
- assert not shared .cmd_opts .hide_ui_dir_config , '--hide-ui-dir-config option must be disabled'
30
- assert input_dir , 'input directory not selected'
31
-
32
- image_list = shared .listfiles (input_dir )
33
- for filename in image_list :
34
- try :
35
- image = Image .open (filename )
36
- except Exception :
37
- continue
38
- image_data .append (image )
39
- image_names .append (filename )
40
- else :
41
- assert image , 'image not selected'
42
-
43
- image_data .append (image )
44
- image_names .append (None )
16
+ def get_images (extras_mode , image , image_folder , input_dir ):
17
+ if extras_mode == 1 :
18
+ for img in image_folder :
19
+ if isinstance (img , Image .Image ):
20
+ image = img
21
+ fn = ''
22
+ else :
23
+ image = Image .open (os .path .abspath (img .name ))
24
+ fn = os .path .splitext (img .orig_name )[0 ]
25
+ yield image , fn
26
+ elif extras_mode == 2 :
27
+ assert not shared .cmd_opts .hide_ui_dir_config , '--hide-ui-dir-config option must be disabled'
28
+ assert input_dir , 'input directory not selected'
29
+
30
+ image_list = shared .listfiles (input_dir )
31
+ for filename in image_list :
32
+ try :
33
+ image = Image .open (filename )
34
+ except Exception :
35
+ continue
36
+ yield image , filename
37
+ else :
38
+ assert image , 'image not selected'
39
+ yield image , None
45
40
46
41
if extras_mode == 2 and output_dir != '' :
47
42
outpath = output_dir
@@ -50,14 +45,16 @@ def run_postprocessing(extras_mode, image, image_folder, input_dir, output_dir,
50
45
51
46
infotext = ''
52
47
53
- for image , name in zip (image_data , image_names ):
48
+ for image_data , name in get_images (extras_mode , image , image_folder , input_dir ):
49
+ image_data : Image .Image
50
+
54
51
shared .state .textinfo = name
55
52
56
- parameters , existing_pnginfo = images .read_info_from_image (image )
53
+ parameters , existing_pnginfo = images .read_info_from_image (image_data )
57
54
if parameters :
58
55
existing_pnginfo ["parameters" ] = parameters
59
56
60
- pp = scripts_postprocessing .PostprocessedImage (image .convert ("RGB" ))
57
+ pp = scripts_postprocessing .PostprocessedImage (image_data .convert ("RGB" ))
61
58
62
59
scripts .scripts_postproc .run (pp , args )
63
60
@@ -78,6 +75,8 @@ def run_postprocessing(extras_mode, image, image_folder, input_dir, output_dir,
78
75
if extras_mode != 2 or show_extras_results :
79
76
outputs .append (pp .image )
80
77
78
+ image_data .close ()
79
+
81
80
devices .torch_gc ()
82
81
83
82
return outputs , ui_common .plaintext_to_html (infotext ), ''
0 commit comments