Skip to content

Commit a75caac

Browse files
committed
Added support for higher resolutions in Image-2-Image mode (can be used for upscaling)
1 parent 43cdfec commit a75caac

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

modules/async_worker.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
outputs = []
1818

1919

20-
def get_image(path):
20+
def get_image(path, megapixels=1.0):
2121
image = None
2222
with open(path, 'rb') as image_file:
2323
pil_image = Image.open(image_file)
@@ -26,7 +26,7 @@ def get_image(path):
2626
image = image.convert("RGB")
2727
image = np.array(image).astype(np.float32) / 255.0
2828
image = torch.from_numpy(image)[None,]
29-
image = core.upscale(image)
29+
image = core.upscale(image, megapixels)
3030
return image
3131

3232

@@ -243,6 +243,12 @@ def handler(task):
243243
resolution = default_settings['resolution']
244244
width, height = string_to_dimensions(resolution)
245245

246+
img2img_megapixels = width * height / 2**20
247+
if img2img_megapixels < constants.MIN_MEGAPIXELS:
248+
img2img_megapixels = constants.MIN_MEGAPIXELS
249+
elif img2img_megapixels > constants.MAX_MEGAPIXELS:
250+
img2img_megapixels = constants.MAX_MEGAPIXELS
251+
246252
pipeline.clear_all_caches() # save memory
247253

248254
results = []
@@ -278,7 +284,7 @@ def callback(step, x0, x, total_steps, y):
278284

279285
input_image = None
280286
if input_image_path != None:
281-
input_image = get_image(input_image_path)
287+
input_image = get_image(input_image_path, img2img_megapixels)
282288

283289
execution_start_time = time.perf_counter()
284290
try:

modules/constants.py

+4
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@
88

99
# exclusive, needed by modules\expansion.py -> transformers\trainer_utils.py -> np.random.seed()
1010
SEED_LIMIT_NUMPY = 2**32
11+
12+
# min - native SDXL resolution, max - determined by SDXL context size (2048)
13+
MIN_MEGAPIXELS = 1.0
14+
MAX_MEGAPIXELS = 4.0

update_log_mre.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### 2.0.12 MRE
2+
3+
* Added support for higher resolutions in Image-2-Image mode (can be used for upscaling).
4+
15
### 2.0.0 MRE
26

37
* Changed Prompt Expansion (aka Fooocus V2) to be enabled by default.

0 commit comments

Comments
 (0)