MCPcopy Create free account
hub / github.com/DenOfEquity/ersatzForge / run

Method run

scripts/sd_upscale.py:27–105  ·  view source on GitHub ↗
(self, p, width, height, overlap, scale, upscaler_index)

Source from the content-addressed store, hash-verified

25 return [width, height, overlap, scale, upscaler_index]
26
27 def run(self, p, width, height, overlap, scale, upscaler_index):
28 if isinstance(upscaler_index, str):
29 upscaler_index = [x.name.lower() for x in shared.sd_upscalers].index(upscaler_index.lower())
30 processing.fix_seed(p)
31 upscaler = shared.sd_upscalers[upscaler_index]
32
33 p.extra_generation_params["SD Upscale"] = (scale, upscaler.name, width, height, overlap)
34
35 seed = p.seed
36
37 init_img = p.init_images[0]
38 init_img = images.flatten(init_img, opts.img2img_background_color)
39
40 if upscaler.name != "None":
41 img = upscaler.scaler.upscale(init_img, scale, upscaler.data_path)
42 else:
43 img = init_img
44
45 grid = images.split_grid(img, tile_w=width, tile_h=height, overlap=overlap)
46
47 batch_size = p.batch_size
48 upscale_count = p.n_iter
49 original_width = p.width
50 original_height = p.height
51 p.n_iter = 1
52 p.do_not_save_grid = True
53 p.do_not_save_samples = True
54 p.width = width
55 p.height = height
56
57 work = []
58
59 for _y, _h, row in grid.tiles:
60 for tiledata in row:
61 work.append(tiledata[2])
62
63 batch_count = int((len(work) + batch_size - 1) / batch_size)
64 state.job_count = batch_count * upscale_count
65
66 print(f"[SD Upscale] {upscale_count} output images; {len(work)*upscale_count} total tiles ({len(grid.tiles[0][2])}x{len(grid.tiles)} per image); {state.job_count} total batches.")
67
68 result_images = []
69 infotexts = []
70 for n in range(upscale_count):
71 start_seed = seed + n
72 p.seed = start_seed
73
74 work_results = []
75 for i in range(batch_count):
76 p.batch_size = batch_size
77 p.init_images = work[i * batch_size:(i + 1) * batch_size]
78
79 state.job = f"Batch {i + 1 + n * batch_count} out of {state.job_count}"
80 processed = processing.process_images(p)
81
82 if i == 0:
83 infotexts.append(processed.info.replace(f"Size: {width}x{height}", f"Size: {original_width}x{original_height}", 1))
84

Callers

nothing calls this directly

Calls 3

ProcessedClass · 0.90
flattenMethod · 0.80
upscaleMethod · 0.45

Tested by

no test coverage detected