README.md: fix demo code. (#4)
Browse files- README.md: fix demo code. (882cfb5b77c33cc95407ed19777c380dfecb187a)
Co-authored-by: Barak Weiss <[email protected]>
README.md
CHANGED
|
@@ -136,14 +136,20 @@ pipe.to("cuda")
|
|
| 136 |
pipe_upsample.to("cuda")
|
| 137 |
pipe.vae.enable_tiling()
|
| 138 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
prompt = "The video depicts a winding mountain road covered in snow, with a single vehicle traveling along it. The road is flanked by steep, rocky cliffs and sparse vegetation. The landscape is characterized by rugged terrain and a river visible in the distance. The scene captures the solitude and beauty of a winter drive through a mountainous region."
|
| 140 |
negative_prompt = "worst quality, inconsistent motion, blurry, jittery, distorted"
|
| 141 |
-
expected_height, expected_width =
|
| 142 |
downscale_factor = 2 / 3
|
| 143 |
num_frames = 121
|
| 144 |
|
| 145 |
# Part 1. Generate video at smaller resolution
|
| 146 |
downscaled_height, downscaled_width = int(expected_height * downscale_factor), int(expected_width * downscale_factor)
|
|
|
|
| 147 |
latents = pipe(
|
| 148 |
conditions=None,
|
| 149 |
prompt=prompt,
|
|
@@ -200,6 +206,11 @@ pipe.to("cuda")
|
|
| 200 |
pipe_upsample.to("cuda")
|
| 201 |
pipe.vae.enable_tiling()
|
| 202 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/penguin.png")
|
| 204 |
video = [image]
|
| 205 |
condition1 = LTXVideoCondition(video=video, frame_index=0)
|
|
@@ -254,7 +265,6 @@ video = pipe(
|
|
| 254 |
video = [frame.resize((expected_width, expected_height)) for frame in video]
|
| 255 |
|
| 256 |
export_to_video(video, "output.mp4", fps=24)
|
| 257 |
-
|
| 258 |
```
|
| 259 |
|
| 260 |
### For video-to-video:
|
|
@@ -272,8 +282,8 @@ pipe_upsample.to("cuda")
|
|
| 272 |
pipe.vae.enable_tiling()
|
| 273 |
|
| 274 |
def round_to_nearest_resolution_acceptable_by_vae(height, width):
|
| 275 |
-
height = height - (height % pipe.
|
| 276 |
-
width = width - (width % pipe.
|
| 277 |
return height, width
|
| 278 |
|
| 279 |
video = load_video(
|
|
@@ -331,7 +341,6 @@ video = pipe(
|
|
| 331 |
video = [frame.resize((expected_width, expected_height)) for frame in video]
|
| 332 |
|
| 333 |
export_to_video(video, "output.mp4", fps=24)
|
| 334 |
-
|
| 335 |
```
|
| 336 |
|
| 337 |
|
|
|
|
| 136 |
pipe_upsample.to("cuda")
|
| 137 |
pipe.vae.enable_tiling()
|
| 138 |
|
| 139 |
+
def round_to_nearest_resolution_acceptable_by_vae(height, width):
|
| 140 |
+
height = height - (height % pipe.vae_spatial_compression_ratio)
|
| 141 |
+
width = width - (width % pipe.vae_spatial_compression_ratio)
|
| 142 |
+
return height, width
|
| 143 |
+
|
| 144 |
prompt = "The video depicts a winding mountain road covered in snow, with a single vehicle traveling along it. The road is flanked by steep, rocky cliffs and sparse vegetation. The landscape is characterized by rugged terrain and a river visible in the distance. The scene captures the solitude and beauty of a winter drive through a mountainous region."
|
| 145 |
negative_prompt = "worst quality, inconsistent motion, blurry, jittery, distorted"
|
| 146 |
+
expected_height, expected_width = 512, 704
|
| 147 |
downscale_factor = 2 / 3
|
| 148 |
num_frames = 121
|
| 149 |
|
| 150 |
# Part 1. Generate video at smaller resolution
|
| 151 |
downscaled_height, downscaled_width = int(expected_height * downscale_factor), int(expected_width * downscale_factor)
|
| 152 |
+
downscaled_height, downscaled_width = round_to_nearest_resolution_acceptable_by_vae(downscaled_height, downscaled_width)
|
| 153 |
latents = pipe(
|
| 154 |
conditions=None,
|
| 155 |
prompt=prompt,
|
|
|
|
| 206 |
pipe_upsample.to("cuda")
|
| 207 |
pipe.vae.enable_tiling()
|
| 208 |
|
| 209 |
+
def round_to_nearest_resolution_acceptable_by_vae(height, width):
|
| 210 |
+
height = height - (height % pipe.vae_spatial_compression_ratio)
|
| 211 |
+
width = width - (width % pipe.vae_spatial_compression_ratio)
|
| 212 |
+
return height, width
|
| 213 |
+
|
| 214 |
image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/penguin.png")
|
| 215 |
video = [image]
|
| 216 |
condition1 = LTXVideoCondition(video=video, frame_index=0)
|
|
|
|
| 265 |
video = [frame.resize((expected_width, expected_height)) for frame in video]
|
| 266 |
|
| 267 |
export_to_video(video, "output.mp4", fps=24)
|
|
|
|
| 268 |
```
|
| 269 |
|
| 270 |
### For video-to-video:
|
|
|
|
| 282 |
pipe.vae.enable_tiling()
|
| 283 |
|
| 284 |
def round_to_nearest_resolution_acceptable_by_vae(height, width):
|
| 285 |
+
height = height - (height % pipe.vae_spatial_compression_ratio)
|
| 286 |
+
width = width - (width % pipe.vae_spatial_compression_ratio)
|
| 287 |
return height, width
|
| 288 |
|
| 289 |
video = load_video(
|
|
|
|
| 341 |
video = [frame.resize((expected_width, expected_height)) for frame in video]
|
| 342 |
|
| 343 |
export_to_video(video, "output.mp4", fps=24)
|
|
|
|
| 344 |
```
|
| 345 |
|
| 346 |
|