17
17
outputs = []
18
18
19
19
20
- def get_image (path ):
20
+ def get_image (path , megapixels = 1.0 ):
21
21
image = None
22
22
with open (path , 'rb' ) as image_file :
23
23
pil_image = Image .open (image_file )
@@ -26,7 +26,7 @@ def get_image(path):
26
26
image = image .convert ("RGB" )
27
27
image = np .array (image ).astype (np .float32 ) / 255.0
28
28
image = torch .from_numpy (image )[None ,]
29
- image = core .upscale (image )
29
+ image = core .upscale (image , megapixels )
30
30
return image
31
31
32
32
@@ -243,6 +243,12 @@ def handler(task):
243
243
resolution = default_settings ['resolution' ]
244
244
width , height = string_to_dimensions (resolution )
245
245
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
+
246
252
pipeline .clear_all_caches () # save memory
247
253
248
254
results = []
@@ -278,7 +284,7 @@ def callback(step, x0, x, total_steps, y):
278
284
279
285
input_image = None
280
286
if input_image_path != None :
281
- input_image = get_image (input_image_path )
287
+ input_image = get_image (input_image_path , img2img_megapixels )
282
288
283
289
execution_start_time = time .perf_counter ()
284
290
try :
0 commit comments