r""" Reconstruct video tensors from patch embeddings. Args: x (List[Tensor]): List of patchified features, each with shape [L, C_out * prod(patch_size)] grid_sizes (Tensor): Original spatial-temporal grid dimensions before patc
(self, x, grid_sizes)
| 774 | |
| 775 | |
| 776 | def unpatchify(self, x, grid_sizes): |
| 777 | r""" |
| 778 | Reconstruct video tensors from patch embeddings. |
| 779 | |
| 780 | Args: |
| 781 | x (List[Tensor]): |
| 782 | List of patchified features, each with shape [L, C_out * prod(patch_size)] |
| 783 | grid_sizes (Tensor): |
| 784 | Original spatial-temporal grid dimensions before patching, |
| 785 | shape [B, 3] (3 dimensions correspond to F_patches, H_patches, W_patches) |
| 786 | |
| 787 | Returns: |
| 788 | List[Tensor]: |
| 789 | Reconstructed video tensors with shape [C_out, F, H / 8, W / 8] |
| 790 | """ |
| 791 | |
| 792 | c = self.out_dim |
| 793 | out = [] |
| 794 | for u, v in zip(x, grid_sizes.tolist()): |
| 795 | u = u[:math.prod(v)].view(*v, *self.patch_size, c) |
| 796 | u = torch.einsum('fhwpqrc->cfphqwr', u) |
| 797 | u = u.reshape(c, *[i * j for i, j in zip(v, self.patch_size)]) |
| 798 | out.append(u) |
| 799 | return out |
| 800 | |
| 801 | def init_weights(self): |
| 802 | r""" |