Download vit_up/utils.py from Krispin/vit-up: direct link, hf CLI and curl.
- Browser
- Download file 354 Bytes
-
https://huggingface.co/spaces/Krispin/vit-up/resolve/main/vit_up/utils.py
- Command line
-
hf download hf://spaces/Krispin/vit-up/vit_up/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/Krispin/vit-up/resolve/main/vit_up/utils.py
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) | |