vit-up / vit_up /utils.py
Krispin's picture
Use the ViT-Up Stage 2 model, allow output resolutions up to 1008, drop the resized-input output
a2d7e15 verified
Raw History Blame Contribute Delete
354 Bytes
import torch
def regular_grid(size: int, device=None) -> torch.Tensor:
"""Normalized (x, y) centers of a size x size grid of cells, shape (size, size, 2)."""
centers = (torch.arange(size, dtype=torch.float32, device=device) + 0.5) * (1.0 / size)
y, x = torch.meshgrid(centers, centers, indexing="ij")
return torch.stack((x, y), dim=-1)