MCPcopy Index your code
hub / github.com/vladmandic/sdnext / run_postprocessing

Function run_postprocessing

modules/postprocessing.py:12–100  ·  view source on GitHub ↗
(extras_mode, image, image_folder: list[tempfile.NamedTemporaryFile], input_dir, output_dir, show_extras_results, *args, save_output: bool = True)

Source from the content-addressed store, hash-verified

10
11
12def run_postprocessing(extras_mode, image, image_folder: list[tempfile.NamedTemporaryFile], input_dir, output_dir, show_extras_results, *args, save_output: bool = True):
13 devices.torch_gc()
14 shared.state.begin('Extras')
15 image_data = []
16 image_names = []
17 image_fullnames = []
18 image_ext = []
19 outputs = []
20 params = {}
21 info = ''
22 if extras_mode == 1:
23 for img in image_folder:
24 if isinstance(img, Image.Image):
25 image = img
26 fn = ''
27 ext = None
28 else:
29 try:
30 image = Image.open(os.path.abspath(img.name))
31 except Exception as e:
32 log.error(f'Failed to open image: file="{img.name}" {e}')
33 continue
34 fn, ext = os.path.splitext(img.orig_name)
35 image_fullnames.append(img.name)
36 image_data.append(image)
37 image_names.append(fn)
38 image_ext.append(ext)
39 log.debug(f'Process: mode=batch inputs={len(image_folder)} images={len(image_data)}')
40 elif extras_mode == 2:
41 assert input_dir, 'input directory not selected'
42 image_list = os.listdir(input_dir)
43 for filename in image_list:
44 fn = os.path.join(input_dir, filename)
45 try:
46 image = Image.open(fn)
47 except Exception as e:
48 log.error(f'Failed to open image: file="{fn}" {e}')
49 continue
50 image_fullnames.append(fn)
51 image_data.append(image)
52 image_names.append(fn)
53 image_ext.append(None)
54 log.debug(f'Process: mode=folder inputs={input_dir} files={len(image_list)} images={len(image_data)}')
55 else:
56 image_data.append(image)
57 image_names.append(None)
58 image_ext.append(None)
59 if extras_mode == 2 and output_dir != '':
60 outpath = output_dir
61 else:
62 outpath = resolve_output_path(opts.outdir_samples, opts.outdir_extras_samples)
63 processed_images = []
64 for image, name, ext in zip(image_data, image_names, image_ext, strict=False): # pylint: disable=redefined-argument-from-local
65 log.debug(f'Process: image={image} {args}')
66 info = ''
67 if shared.state.interrupted:
68 log.debug('Postprocess interrupted')
69 break

Callers 1

run_extrasFunction · 0.85

Calls 10

resolve_output_pathFunction · 0.90
beginMethod · 0.80
itemsMethod · 0.80
save_imageMethod · 0.80
convertMethod · 0.45
runMethod · 0.45
parseMethod · 0.45
getMethod · 0.45
closeMethod · 0.45
postprocessMethod · 0.45

Tested by

no test coverage detected