cache_3d
¶
This module implements the 3D cache system for GEN3C video generation with camera control. The cache maintains a point cloud representation of the scene, enabling: - Unprojecting depth maps to 3D world points - Forward warping rendered views to new camera poses - Managing multiple frame buffers for temporal consistency
Classes¶
fastvideo.pipelines.basic.gen3c.cache_3d.Cache3DBase
¶
Cache3DBase(input_image: Tensor, input_depth: Tensor, input_w2c: Tensor, input_intrinsics: Tensor, input_mask: Tensor | None = None, input_format: list[str] | None = None, input_points: Tensor | None = None, weight_dtype: dtype = float32, is_depth: bool = True, device: str = 'cuda', filter_points_threshold: float = 1.0)
Base class for 3D cache management.
The cache maintains: - input_image: RGB images stored in the cache - input_points: 3D world coordinates for each pixel - input_mask: Validity mask for each pixel
Initialize the 3D cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_image
|
Tensor
|
Input image tensor with varying dimensions |
required |
input_depth
|
Tensor
|
Depth map tensor |
required |
input_w2c
|
Tensor
|
World-to-camera transformation matrix |
required |
input_intrinsics
|
Tensor
|
Camera intrinsic matrix |
required |
input_mask
|
Tensor | None
|
Optional validity mask |
None
|
input_format
|
list[str] | None
|
Dimension labels for input_image (e.g., ['B', 'C', 'H', 'W']) |
None
|
input_points
|
Tensor | None
|
Pre-computed 3D world points (alternative to depth) |
None
|
weight_dtype
|
dtype
|
Data type for computations |
float32
|
is_depth
|
bool
|
If True, input_depth is z-depth; if False, it's distance |
True
|
device
|
str
|
Computation device |
'cuda'
|
filter_points_threshold
|
float
|
Threshold for filtering unreliable depth |
1.0
|
Source code in fastvideo/pipelines/basic/gen3c/cache_3d.py
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 | |
Functions¶
fastvideo.pipelines.basic.gen3c.cache_3d.Cache3DBase.render_cache
¶
render_cache(target_w2cs: Tensor, target_intrinsics: Tensor, render_depth: bool = False, start_frame_idx: int = 0) -> tuple[Tensor, Tensor]
Render the cached 3D points from new camera viewpoints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_w2cs
|
Tensor
|
(b, F_target, 4, 4) target camera transformations |
required |
target_intrinsics
|
Tensor
|
(b, F_target, 3, 3) target camera intrinsics |
required |
render_depth
|
bool
|
If True, return depth instead of RGB |
False
|
start_frame_idx
|
int
|
Starting frame index in the cache |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
pixels |
Tensor
|
(b, F_target, N, c, h, w) rendered images or depth |
masks |
Tensor
|
(b, F_target, N, 1, h, w) validity masks |
Source code in fastvideo/pipelines/basic/gen3c/cache_3d.py
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 | |
fastvideo.pipelines.basic.gen3c.cache_3d.Cache3DBase.update_cache
¶
fastvideo.pipelines.basic.gen3c.cache_3d.Cache3DBuffer
¶
Cache3DBuffer(frame_buffer_max: int = 2, noise_aug_strength: float = 0.0, generator: Generator | None = None, **kwargs)
Bases: Cache3DBase
3D cache with frame buffer support.
This class manages multiple frame buffers for temporal consistency and supports noise augmentation for training stability.
Initialize the buffered 3D cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame_buffer_max
|
int
|
Maximum number of frames to buffer |
2
|
noise_aug_strength
|
float
|
Strength of noise augmentation per buffer |
0.0
|
generator
|
Generator | None
|
Random generator for reproducibility |
None
|
**kwargs
|
Arguments passed to Cache3DBase |
{}
|
Source code in fastvideo/pipelines/basic/gen3c/cache_3d.py
Functions¶
fastvideo.pipelines.basic.gen3c.cache_3d.Cache3DBuffer.render_cache
¶
render_cache(target_w2cs: Tensor, target_intrinsics: Tensor, render_depth: bool = False, start_frame_idx: int = 0) -> tuple[Tensor, Tensor]
Render the cache with optional noise augmentation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_w2cs
|
Tensor
|
(b, F_target, 4, 4) target camera transformations |
required |
target_intrinsics
|
Tensor
|
(b, F_target, 3, 3) target camera intrinsics |
required |
render_depth
|
bool
|
If True, return depth instead of RGB |
False
|
start_frame_idx
|
int
|
Starting frame index (must be 0 for this class) |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
pixels |
Tensor
|
(b, F_target, N, c, h, w) rendered images |
masks |
Tensor
|
(b, F_target, N, 1, h, w) validity masks |
Source code in fastvideo/pipelines/basic/gen3c/cache_3d.py
fastvideo.pipelines.basic.gen3c.cache_3d.Cache3DBuffer.update_cache
¶
update_cache(new_image: Tensor, new_depth: Tensor, new_w2c: Tensor, new_mask: Tensor | None = None, new_intrinsics: Tensor | None = None)
Update the cache with a new frame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new_image
|
Tensor
|
(B, C, H, W) new RGB image |
required |
new_depth
|
Tensor
|
(B, 1, H, W) new depth map |
required |
new_w2c
|
Tensor
|
(B, 4, 4) new world-to-camera transformation |
required |
new_mask
|
Tensor | None
|
Optional (B, 1, H, W) validity mask |
None
|
new_intrinsics
|
Tensor | None
|
(B, 3, 3) camera intrinsics (optional) |
None
|
Source code in fastvideo/pipelines/basic/gen3c/cache_3d.py
Functions¶
fastvideo.pipelines.basic.gen3c.cache_3d.bilinear_splatting
¶
bilinear_splatting(frame1: Tensor, mask1: Tensor | None, depth1: Tensor, flow12: Tensor, flow12_mask: Tensor | None = None, is_image: bool = False, depth_weight_scale: float = 50.0) -> tuple[Tensor, Tensor]
Bilinear splatting for forward warping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame1
|
Tensor
|
(b, c, h, w) source frame |
required |
mask1
|
Tensor | None
|
(b, 1, h, w) valid pixel mask (1 for known, 0 for unknown) |
required |
depth1
|
Tensor
|
(b, 1, h, w) depth map |
required |
flow12
|
Tensor
|
(b, 2, h, w) optical flow from frame1 to frame2 |
required |
flow12_mask
|
Tensor | None
|
(b, 1, h, w) flow validity mask |
None
|
is_image
|
bool
|
If True, output will be clipped to (-1, 1) range |
False
|
depth_weight_scale
|
float
|
Scale factor for depth weighting |
50.0
|
Returns:
| Name | Type | Description |
|---|---|---|
warped_frame2 |
Tensor
|
(b, c, h, w) warped frame |
mask2 |
Tensor
|
(b, 1, h, w) validity mask for warped frame |
Source code in fastvideo/pipelines/basic/gen3c/cache_3d.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
fastvideo.pipelines.basic.gen3c.cache_3d.create_grid
¶
Create a dense grid of (x, y) coordinates of shape (b, 2, h, w).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
b
|
int
|
Batch size |
required |
h
|
int
|
Height |
required |
w
|
int
|
Width |
required |
device
|
str
|
Device for tensor creation |
'cpu'
|
dtype
|
dtype
|
Data type for tensor |
float32
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Grid tensor of shape (b, 2, h, w) |
Source code in fastvideo/pipelines/basic/gen3c/cache_3d.py
fastvideo.pipelines.basic.gen3c.cache_3d.forward_warp
¶
forward_warp(frame1: Tensor, mask1: Tensor | None, depth1: Tensor | None, transformation1: Tensor | None, transformation2: Tensor, intrinsic1: Tensor | None, intrinsic2: Tensor | None, is_image: bool = True, is_depth: bool = True, render_depth: bool = False, world_points1: Tensor | None = None) -> tuple[Tensor, Tensor, Tensor | None, Tensor]
Forward warp frame1 to a new view defined by transformation2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame1
|
Tensor
|
(b, c, h, w) source frame in range [-1, 1] for images |
required |
mask1
|
Tensor | None
|
(b, 1, h, w) valid pixel mask |
required |
depth1
|
Tensor | None
|
(b, 1, h, w) depth map (required if world_points1 is None) |
required |
transformation1
|
Tensor | None
|
(b, 4, 4) source camera w2c (required if depth1 is provided) |
required |
transformation2
|
Tensor
|
(b, 4, 4) target camera w2c |
required |
intrinsic1
|
Tensor | None
|
(b, 3, 3) source camera intrinsics |
required |
intrinsic2
|
Tensor | None
|
(b, 3, 3) target camera intrinsics |
required |
is_image
|
bool
|
If True, output will be clipped to (-1, 1) |
True
|
is_depth
|
bool
|
If True, depth1 is z-depth; if False, it's distance |
True
|
render_depth
|
bool
|
If True, also return the warped depth map |
False
|
world_points1
|
Tensor | None
|
(b, h, w, 3) pre-computed world points (alternative to depth1) |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
warped_frame2 |
Tensor
|
(b, c, h, w) warped frame |
mask2 |
Tensor
|
(b, 1, h, w) validity mask |
warped_depth2 |
Tensor | None
|
(b, h, w) warped depth (if render_depth=True) |
flow12 |
Tensor
|
(b, 2, h, w) optical flow |
Source code in fastvideo/pipelines/basic/gen3c/cache_3d.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | |
fastvideo.pipelines.basic.gen3c.cache_3d.inverse_with_conversion
¶
Compute matrix inverse with float32 conversion for numerical stability.
fastvideo.pipelines.basic.gen3c.cache_3d.project_points
¶
Project 3D world points to 2D pixel coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
world_points
|
Tensor
|
(b, h, w, 3) 3D world coordinates |
required |
w2c
|
Tensor
|
(b, 4, 4) world-to-camera transformation matrix |
required |
intrinsic
|
Tensor
|
(b, 3, 3) camera intrinsic matrix |
required |
Returns:
| Name | Type | Description |
|---|---|---|
projected_points |
Tensor
|
(b, h, w, 3, 1) projected 2D coordinates (x, y, z) |
Source code in fastvideo/pipelines/basic/gen3c/cache_3d.py
fastvideo.pipelines.basic.gen3c.cache_3d.reliable_depth_mask_range_batch
¶
reliable_depth_mask_range_batch(depth: Tensor, window_size: int = 5, ratio_thresh: float = 0.05, eps: float = 1e-06) -> Tensor
Compute a mask for reliable depth values based on local variation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
depth
|
Tensor
|
(b, h, w) or (b, 1, h, w) depth map |
required |
window_size
|
int
|
Size of the local window (must be odd) |
5
|
ratio_thresh
|
float
|
Threshold for depth variation ratio |
0.05
|
eps
|
float
|
Small epsilon for numerical stability |
1e-06
|
Returns:
| Name | Type | Description |
|---|---|---|
reliable_mask |
Tensor
|
Boolean mask where True indicates reliable depth |
Source code in fastvideo/pipelines/basic/gen3c/cache_3d.py
fastvideo.pipelines.basic.gen3c.cache_3d.unproject_points
¶
unproject_points(depth: Tensor, w2c: Tensor, intrinsic: Tensor, is_depth: bool = True, mask: Tensor | None = None) -> Tensor
Unproject depth map to 3D world points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
depth
|
Tensor
|
(b, 1, h, w) depth map |
required |
w2c
|
Tensor
|
(b, 4, 4) world-to-camera transformation matrix |
required |
intrinsic
|
Tensor
|
(b, 3, 3) camera intrinsic matrix |
required |
is_depth
|
bool
|
If True, depth is z-depth; if False, depth is distance to camera |
True
|
mask
|
Tensor | None
|
Optional (b, h, w) or (b, 1, h, w) mask for valid pixels |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
world_points |
Tensor
|
(b, h, w, 3) 3D world coordinates |