Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions scripts/webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ def classToArrays( items, seed, n_iter ):
return all_seeds, n_iter, prompt_matrix_parts, all_prompts, needrows

def perform_masked_image_restoration(image, init_img, init_mask, mask_blur_strength, mask_restore, use_RealESRGAN, RealESRGAN):
if not mask_restore:
if not mask_restore:
return image
else:
init_mask = init_mask.filter(ImageFilter.GaussianBlur(mask_blur_strength))
Expand Down Expand Up @@ -840,7 +840,7 @@ def perform_color_correction(img_rgb, correction_target_lab, do_color_correction
except:
print("Install scikit-image to perform color correction")
return img_rgb

if not do_color_correction: return img_rgb
if correction_target_lab is None: return img_rgb

Expand All @@ -854,7 +854,7 @@ def perform_color_correction(img_rgb, correction_target_lab, do_color_correction
channel_axis=2
), cv2.COLOR_LAB2RGB).astype("uint8")
)
)
)

def process_images(
outpath, func_init, func_sample, prompt, seed, sampler_name, skip_grid, skip_save, batch_size,
Expand Down Expand Up @@ -1027,7 +1027,7 @@ def check_safety(x_image):
while(torch.cuda.memory_allocated()/1e6 >= mem):
time.sleep(1)

cur_variant_amount = variant_amount
cur_variant_amount = variant_amount
if variant_amount == 0.0:
# we manually generate all input noises because each one should have a specific seed
x = create_random_tensors(shape, seeds=seeds)
Expand Down Expand Up @@ -1114,10 +1114,10 @@ def check_safety(x_image):
gfpgan_image = Image.fromarray(gfpgan_sample)
gfpgan_image = perform_color_correction(gfpgan_image, correction_target, do_color_correction)
gfpgan_image = perform_masked_image_restoration(
gfpgan_image, init_img, init_mask,
gfpgan_image, init_img, init_mask,
mask_blur_strength, mask_restore,
use_RealESRGAN = False, RealESRGAN = None
)
)
gfpgan_metadata = copy.copy(metadata)
gfpgan_metadata.GFPGAN = True
ImageMetadata.set_on_image( gfpgan_image, gfpgan_metadata )
Expand All @@ -1137,7 +1137,7 @@ def check_safety(x_image):
esrgan_image = Image.fromarray(esrgan_sample)
esrgan_image = perform_color_correction(esrgan_image, correction_target, do_color_correction)
esrgan_image = perform_masked_image_restoration(
esrgan_image, init_img, init_mask,
esrgan_image, init_img, init_mask,
mask_blur_strength, mask_restore,
use_RealESRGAN, RealESRGAN
)
Expand All @@ -1159,7 +1159,7 @@ def check_safety(x_image):
gfpgan_esrgan_image = Image.fromarray(gfpgan_esrgan_sample)
gfpgan_esrgan_image = perform_color_correction(gfpgan_esrgan_image, correction_target, do_color_correction)
gfpgan_esrgan_image = perform_masked_image_restoration(
gfpgan_esrgan_image, init_img, init_mask,
gfpgan_esrgan_image, init_img, init_mask,
mask_blur_strength, mask_restore,
use_RealESRGAN, RealESRGAN
)
Expand All @@ -1175,7 +1175,7 @@ def check_safety(x_image):
output_images.append(image)

image = perform_masked_image_restoration(
image, init_img, init_mask,
image, init_img, init_mask,
mask_blur_strength, mask_restore,
# RealESRGAN image already processed in if-case above.
use_RealESRGAN = False, RealESRGAN = None
Expand Down Expand Up @@ -1505,7 +1505,7 @@ def init():
#let's try and find where init_image is 0's
#shape is probably (3,width,height)?

if image_editor_mode == "Uncrop":
if image_editor_mode == "Uncrop":
_image=image.numpy()[0]
_mask=np.ones((_image.shape[1],_image.shape[2]))

Expand All @@ -1526,7 +1526,7 @@ def init():
boundingbox=np.zeros(shape=(height,width))
boundingbox[colstart+PAD_IMG:colend-PAD_IMG,rowstart+PAD_IMG:rowend-PAD_IMG]=1
boundingbox=blurArr(boundingbox,4)

#this is the mask for outpainting
PAD_MASK=24
boundingbox2=np.zeros(shape=(height,width))
Expand Down Expand Up @@ -1557,7 +1557,7 @@ def init():
init_image = init_image.to(device)
init_image = repeat(init_image, '1 ... -> b ...', b=batch_size)
init_latent = (model if not opt.optimized else modelFS).get_first_stage_encoding((model if not opt.optimized else modelFS).encode_first_stage(init_image)) # move to latent space

if opt.optimized:
mem = torch.cuda.memory_allocated()/1e6
modelFS.to("cpu")
Expand Down Expand Up @@ -1617,7 +1617,7 @@ def sample(init_data, x, conditioning, unconditional_conditioning, sampler_name)

# turn on color correction for loopback to prevent known issue of color drift
do_color_correction = True

for i in range(n_iter):
if do_color_correction and i == 0:
correction_target = cv2.cvtColor(np.asarray(init_img.copy()), cv2.COLOR_RGB2LAB)
Expand Down Expand Up @@ -1658,9 +1658,9 @@ def sample(init_data, x, conditioning, unconditional_conditioning, sampler_name)
write_info_files=write_info_files,
write_sample_info_to_log_file=write_sample_info_to_log_file,
jpg_sample=jpg_sample,
job_info=job_info,
job_info=job_info,
do_color_correction=do_color_correction,
correction_target=correction_target
correction_target=correction_target
)

if initial_seed is None:
Expand Down Expand Up @@ -2074,7 +2074,7 @@ def processLDSR(image):
if 1 in imgproc_toggles:
if imgproc_upscale_toggles == 0:
ModelLoader(['GFPGAN','LDSR'],False,True) # Unload unused models
ModelLoader(['RealESGAN'],True,False,imgproc_realesrgan_model_name) # Load used models
ModelLoader(['RealESGAN'],True,False,imgproc_realesrgan_model_name) # Load used models
elif imgproc_upscale_toggles == 1:
ModelLoader(['GFPGAN','LDSR'],False,True) # Unload unused models
ModelLoader(['RealESGAN','model'],True,False) # Load used models
Expand Down Expand Up @@ -2306,7 +2306,7 @@ def run_RealESRGAN(image, model_name: str):
'Write sample info files',
'Write sample info to one file',
'jpg samples',
'Color correction (always enabled on loopback mode)'
'Color correction (always enabled on loopback mode)',
'Filter NSFW content',
]
# removed for now becuase of Image Lab implementation
Expand Down Expand Up @@ -2412,7 +2412,7 @@ def run(self):
'inbrowser': opt.inbrowser,
'server_name': '0.0.0.0',
'server_port': opt.port,
'share': opt.share,
'share': opt.share,
'show_error': True
}
if not opt.share:
Expand Down