Skip to content

Official repository for LTX-Video

Inference: Support noise augmentation in image to video.

Sapir Weissbucha18159c0432d
diff --git a/inference.py b/inference.py
index ec82013..dcf0683 100644
--- a/inference.py
+++ b/inference.py
@@ -205,6 +205,12 @@ def main():
default=3,
help="Guidance scale for the pipeline",
)
+ parser.add_argument(
+ "--image_cond_noise_scale",
+ type=float,
+ default=0.15,
+ help="Amount of noise to add to the conditioned image",
+ )
parser.add_argument(
"--height",
type=int,
@@ -365,6 +371,7 @@ def main():
if media_items is not None
else ConditioningMethod.UNCONDITIONAL
),
+ image_cond_noise_scale=args.image_cond_noise_scale,
mixed_precision=not args.bfloat16,
).images
diff --git a/ltx_video/pipelines/pipeline_ltx_video.py b/ltx_video/pipelines/pipeline_ltx_video.py
index 119f700..f0e7832 100644
--- a/ltx_video/pipelines/pipeline_ltx_video.py
+++ b/ltx_video/pipelines/pipeline_ltx_video.py
@@ -655,6 +655,26 @@ class LTXVideoPipeline(DiffusionPipeline):
return caption.strip()
+ def image_cond_noise_update(
+ self,
+ t,
+ init_latents,
+ latents,
+ noise_scale,
+ conditiong_mask,
+ generator,
+ ):
+ noise = randn_tensor(
+ latents.shape,
+ generator=generator,
+ device=latents.device,
+ dtype=latents.dtype,
+ )
+ latents = (init_latents + noise_scale * noise * (t**2)) * conditiong_mask[
+ ..., None
+ ] + latents * (1 - conditiong_mask[..., None])
+ return latents
+
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.prepare_latents
def prepare_latents(
self,
@@ -897,6 +917,7 @@ class LTXVideoPipeline(DiffusionPipeline):
self.video_scale_factor = self.video_scale_factor if is_video else 1
conditioning_method = kwargs.get("conditioning_method", None)
vae_per_channel_normalize = kwargs.get("vae_per_channel_normalize", False)
+ image_cond_noise_scale = kwargs.get("image_cond_noise_scale", 0.0)
init_latents, conditioning_mask = self.prepare_conditioning(
media_items,
num_frames,
@@ -924,6 +945,7 @@ class LTXVideoPipeline(DiffusionPipeline):
latents=init_latents,
latents_mask=conditioning_mask,
)
+ orig_conditiong_mask = conditioning_mask
if conditioning_mask is not None and is_video:
assert num_images_per_prompt == 1
conditioning_mask = (
@@ -954,6 +976,15 @@ class LTXVideoPipeline(DiffusionPipeline):
with self.progress_bar(total=num_inference_steps) as progress_bar:
for i, t in enumerate(timesteps):
+ if conditioning_method == ConditioningMethod.FIRST_FRAME:
+ latents = self.image_cond_noise_update(
+ t,
+ init_latents,
+ latents,
+ image_cond_noise_scale,
+ orig_conditiong_mask,
+ generator,
+ )
latent_model_input = (
torch.cat([latents] * 2) if do_classifier_free_guidance else latents
)