branch1 crossfeeding

This commit is contained in:
Johannes Stelzer 2023-01-10 13:53:29 +01:00
parent 607961feae
commit 18d781f8cd
2 changed files with 25 additions and 20 deletions

View File

@ -75,7 +75,7 @@ class BlendingFrontend():
self.state_prev = {}
self.state_current = {}
self.showing_current = True
self.branch2_independence = False
self.branch1_influence = 0.0
self.imgs_show_last = []
self.imgs_show_current = []
self.nmb_branches_final = 13
@ -92,11 +92,11 @@ class BlendingFrontend():
self.width = 420
def init_diffusion(self):
# fp_ckpt = "../stable_diffusion_models/ckpt/v2-1_512-ema-pruned.ckpt"
# fp_config = 'configs/v2-inference.yaml'
fp_ckpt = "../stable_diffusion_models/ckpt/v2-1_512-ema-pruned.ckpt"
fp_config = 'configs/v2-inference.yaml'
fp_ckpt = "../stable_diffusion_models/ckpt/v2-1_768-ema-pruned.ckpt"
fp_config = 'configs/v2-inference-v.yaml'
# fp_ckpt = "../stable_diffusion_models/ckpt/v2-1_768-ema-pruned.ckpt"
# fp_config = 'configs/v2-inference-v.yaml'
sdh = StableDiffusionHolder(fp_ckpt, fp_config, num_inference_steps=self.num_inference_steps)
self.lb = LatentBlending(sdh)
@ -123,10 +123,10 @@ class BlendingFrontend():
self.mid_compression_scaler = value
print(f"changed mid_compression_scaler to {value}")
def change_branch2_independence(self):
self.branch2_independence = not self.branch2_independence
self.lb.branch2_independence = self.branch2_independence
print(f"changed branch2_independence to {self.branch2_independence}")
def change_branch1_influence(self, value):
self.branch1_influence = value
print(f"changed branch1_influence to {value}")
def change_height(self, value):
self.height = value
@ -205,6 +205,7 @@ class BlendingFrontend():
self.lb.guidance_scale = self.guidance_scale
self.lb.guidance_scale_mid_damper = self.guidance_scale_mid_damper
self.lb.mid_compression_scaler = self.mid_compression_scaler
self.lb.branch1_influence = self.branch1_influence
fixed_seeds = [self.seed1, self.seed2]
imgs_transition = self.lb.run_transition(fixed_seeds=fixed_seeds)
@ -295,21 +296,23 @@ with gr.Blocks() as demo:
negative_prompt = gr.Textbox(label="negative prompt")
with gr.Row():
num_inference_steps = gr.Slider(5, 100, self.num_inference_steps, step=1, label='num_inference_steps', interactive=True)
guidance_scale = gr.Slider(1, 25, self.guidance_scale, step=0.1, label='guidance_scale', interactive=True)
nmb_branches_final = gr.Slider(5, 125, self.nmb_branches_final, step=4, label='nmb trans images', interactive=True)
height = gr.Slider(256, 2048, self.height, step=128, label='height', interactive=True)
width = gr.Slider(256, 2048, self.width, step=128, label='width', interactive=True)
with gr.Row():
num_inference_steps = gr.Slider(5, 100, self.num_inference_steps, step=1, label='num_inference_steps', interactive=True)
guidance_scale = gr.Slider(1, 25, self.guidance_scale, step=0.1, label='guidance_scale', interactive=True)
branch1_influence = gr.Slider(0.0, 1.0, self.branch1_influence, step=0.01, label='branch1_influence', interactive=True)
with gr.Row():
depth_strength = gr.Slider(0.01, 0.99, self.depth_strength, step=0.01, label='depth_strength', interactive=True)
nmb_branches_final = gr.Slider(5, 125, self.nmb_branches_final, step=4, label='nmb trans images', interactive=True)
guidance_scale_mid_damper = gr.Slider(0.01, 2.0, self.guidance_scale_mid_damper, step=0.01, label='guidance_scale_mid_damper', interactive=True)
mid_compression_scaler = gr.Slider(1.0, 2.0, self.mid_compression_scaler, step=0.01, label='mid_compression_scaler', interactive=True)
with gr.Row():
b_newseed1 = gr.Button("rand seed 1")
seed1 = gr.Number(42, label="seed 1", interactive=True)
branch2_independence = gr.Checkbox(label="branch2 independence", interactive=True)
b_newseed2 = gr.Button("rand seed 2")
seed2 = gr.Number(420, label="seed 2", interactive=True)
b_compare = gr.Button("compare")
@ -353,7 +356,7 @@ with gr.Blocks() as demo:
seed2.change(fn=self.change_seed2, inputs=seed2)
fps.change(fn=self.change_fps, inputs=fps)
duration.change(fn=self.change_duration, inputs=duration)
branch2_independence.change(fn=self.change_branch2_independence)
branch1_influence.change(fn=self.change_branch1_influence, inputs=branch1_influence)
b_newseed1.click(self.randomize_seed1, outputs=seed1)
b_newseed2.click(self.randomize_seed2, outputs=seed2)

View File

@ -103,7 +103,7 @@ class LatentBlending():
self.noise_level_upscaling = 20
self.list_injection_idx = None
self.list_nmb_branches = None
self.branch2_independence = False
self.branch1_influence = 0.0
self.set_guidance_scale(guidance_scale)
self.init_mode()
@ -489,11 +489,13 @@ class LatentBlending():
elif idx_branch == self.list_nmb_branches[0] -1:
self.set_seed(fixed_seeds[1])
list_latents = self.run_diffusion(list_conditionings, idx_stop=idx_stop)
# Inject latents from first branch for very first block
if not self.branch2_independence and idx_branch==1:
list_latents = self.tree_latents[0][0]
else:
list_latents = self.run_diffusion(list_conditionings, idx_stop=idx_stop)
# FIXME: if more than 2 base branches?
if idx_branch==1 and self.branch1_influence > 0:
fract_base_influence = np.clip(self.branch1_influence, 0, 1)
list_latents[-1] = interpolate_spherical(list_latents[-1], self.tree_latents[0][0][-1], fract_base_influence)
else:
# find parents latents
b_parent1, b_parent2 = get_closest_idx(fract_mixing, self.tree_fracts[t_block-1])