File size: 559 Bytes
0161e74 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | ## UTILS
import torch
from torch import nn
import torch.nn.functional as F
class PixelDownsampleEncoder(nn.Module):
def __init__(
self,
):
super().__init__()
@torch.compile()
@torch.no_grad()
def encode(self, x: torch.Tensor) -> torch.Tensor:
# normalize input
# x : b c h w
x = F.interpolate(x, size=(64, 64), mode='area')
B, C, H, W = x.shape
p = 4 # patch size
z = x.view(B, C, H // p, p, W // p, p).permute(0, 1, 3, 5, 2, 4).reshape(B, 48, 16, 16)
return z
|