(self, x, feat_cache=None, feat_idx=[0])
| 431 | CausalConv3d(out_dim, 3, 3, padding=1)) |
| 432 | |
| 433 | def forward(self, x, feat_cache=None, feat_idx=[0]): |
| 434 | ## conv1 |
| 435 | if feat_cache is not None: |
| 436 | idx = feat_idx[0] |
| 437 | cache_x = x[:, :, -CACHE_T:, :, :].clone() |
| 438 | if cache_x.shape[2] < 2 and feat_cache[idx] is not None: |
| 439 | # cache last frame of last two chunk |
| 440 | cache_x = torch.cat([ |
| 441 | feat_cache[idx][:, :, -1, :, :].unsqueeze(2).to( |
| 442 | cache_x.device), cache_x |
| 443 | ], |
| 444 | dim=2) |
| 445 | x = self.conv1(x, feat_cache[idx]) |
| 446 | feat_cache[idx] = cache_x |
| 447 | feat_idx[0] += 1 |
| 448 | else: |
| 449 | x = self.conv1(x) |
| 450 | |
| 451 | ## middle |
| 452 | for layer in self.middle: |
| 453 | if check_is_instance(layer, ResidualBlock) and feat_cache is not None: |
| 454 | x = layer(x, feat_cache, feat_idx) |
| 455 | else: |
| 456 | x = layer(x) |
| 457 | |
| 458 | ## upsamples |
| 459 | for layer in self.upsamples: |
| 460 | if feat_cache is not None: |
| 461 | x = layer(x, feat_cache, feat_idx) |
| 462 | else: |
| 463 | x = layer(x) |
| 464 | |
| 465 | ## head |
| 466 | for layer in self.head: |
| 467 | if check_is_instance(layer, CausalConv3d) and feat_cache is not None: |
| 468 | idx = feat_idx[0] |
| 469 | cache_x = x[:, :, -CACHE_T:, :, :].clone() |
| 470 | if cache_x.shape[2] < 2 and feat_cache[idx] is not None: |
| 471 | # cache last frame of last two chunk |
| 472 | cache_x = torch.cat([ |
| 473 | feat_cache[idx][:, :, -1, :, :].unsqueeze(2).to( |
| 474 | cache_x.device), cache_x |
| 475 | ], |
| 476 | dim=2) |
| 477 | x = layer(x, feat_cache[idx]) |
| 478 | feat_cache[idx] = cache_x |
| 479 | feat_idx[0] += 1 |
| 480 | else: |
| 481 | x = layer(x) |
| 482 | return x |
| 483 | |
| 484 | |
| 485 | def count_conv3d(model): |
nothing calls this directly
no test coverage detected