mirror of
https://github.com/lllyasviel/Fooocus.git
synced 2026-08-16 13:13:16 +02:00
revise noise formulation
revise noise formulation
This commit is contained in:
+14
-14
@@ -270,13 +270,11 @@ refresh_everything(
|
||||
|
||||
@torch.no_grad()
|
||||
@torch.inference_mode()
|
||||
def vae_parse(latent, k=1.0):
|
||||
def vae_parse(latent):
|
||||
if final_refiner_vae is None:
|
||||
result = latent["samples"]
|
||||
else:
|
||||
result = vae_interpose.parse(latent["samples"])
|
||||
if k != 1.0:
|
||||
result = result * k
|
||||
return latent
|
||||
|
||||
result = vae_interpose.parse(latent["samples"])
|
||||
return {'samples': result}
|
||||
|
||||
|
||||
@@ -433,6 +431,8 @@ def process_diffusion(positive_cond, negative_cond, steps, switch, width, height
|
||||
decoded_latent = core.decode_vae(vae=target_model, latent_image=sampled_latent, tiled=tiled)
|
||||
|
||||
if refiner_swap_method == 'vae':
|
||||
modules.patch.eps_record = 'vae'
|
||||
|
||||
if modules.inpaint_worker.current_task is not None:
|
||||
modules.inpaint_worker.current_task.unswap()
|
||||
|
||||
@@ -458,13 +458,9 @@ def process_diffusion(positive_cond, negative_cond, steps, switch, width, height
|
||||
target_model = final_unet
|
||||
print('Use base model to refine itself - this may because of developer mode.')
|
||||
|
||||
# Fooocus' vae parameters
|
||||
k_data = 1.025
|
||||
k_noise = 0.25
|
||||
sampled_latent = vae_parse(sampled_latent)
|
||||
|
||||
k_sigmas = 1.4
|
||||
|
||||
sampled_latent = vae_parse(sampled_latent, k=k_data)
|
||||
|
||||
sigmas = calculate_sigmas(sampler=sampler_name,
|
||||
scheduler=scheduler_name,
|
||||
model=target_model.model,
|
||||
@@ -472,6 +468,9 @@ def process_diffusion(positive_cond, negative_cond, steps, switch, width, height
|
||||
denoise=denoise)[switch:] * k_sigmas
|
||||
len_sigmas = len(sigmas) - 1
|
||||
|
||||
assert isinstance(modules.patch.eps_record, torch.Tensor)
|
||||
residual_noise = modules.patch.eps_record / modules.patch.eps_record.std()
|
||||
|
||||
if modules.inpaint_worker.current_task is not None:
|
||||
modules.inpaint_worker.current_task.swap()
|
||||
|
||||
@@ -481,7 +480,7 @@ def process_diffusion(positive_cond, negative_cond, steps, switch, width, height
|
||||
negative=clip_separate(negative_cond, target_model=target_model.model, target_clip=final_clip),
|
||||
latent=sampled_latent,
|
||||
steps=len_sigmas, start_step=0, last_step=len_sigmas, disable_noise=False, force_full_denoise=True,
|
||||
seed=image_seed + 1, # Avoid artifacts
|
||||
seed=image_seed,
|
||||
denoise=denoise,
|
||||
callback_function=callback,
|
||||
cfg=cfg_scale,
|
||||
@@ -490,7 +489,7 @@ def process_diffusion(positive_cond, negative_cond, steps, switch, width, height
|
||||
previewer_start=switch,
|
||||
previewer_end=steps,
|
||||
sigmas=sigmas,
|
||||
extra_noise=k_noise
|
||||
noise=residual_noise
|
||||
)
|
||||
|
||||
target_model = final_refiner_vae
|
||||
@@ -499,4 +498,5 @@ def process_diffusion(positive_cond, negative_cond, steps, switch, width, height
|
||||
decoded_latent = core.decode_vae(vae=target_model, latent_image=sampled_latent, tiled=tiled)
|
||||
|
||||
images = core.pytorch_to_numpy(decoded_latent)
|
||||
modules.patch.eps_record = None
|
||||
return images
|
||||
|
||||
Reference in New Issue
Block a user