Download src/model/encoder/backbone/croco/masking.py from unity4ar/AnySplat: direct link, hf CLI and curl.
- Browser
- Download file 741 Bytes
-
https://huggingface.co/spaces/unity4ar/AnySplat/resolve/main/src/model/encoder/backbone/croco/masking.py
- Command line
-
hf download hf://spaces/unity4ar/AnySplat/src/model/encoder/backbone/croco/masking.py
-
curl -L -o masking.py https://huggingface.co/spaces/unity4ar/AnySplat/resolve/main/src/model/encoder/backbone/croco/masking.py
741 Bytes
| # Copyright (C) 2022-present Naver Corporation. All rights reserved. | |
| # Licensed under CC BY-NC-SA 4.0 (non-commercial use only). | |
| # -------------------------------------------------------- | |
| # Masking utils | |
| # -------------------------------------------------------- | |
| import torch | |
| import torch.nn as nn | |
| class RandomMask(nn.Module): | |
| """ | |
| random masking | |
| """ | |
| def __init__(self, num_patches, mask_ratio): | |
| super().__init__() | |
| self.num_patches = num_patches | |
| self.num_mask = int(mask_ratio * self.num_patches) | |
| def __call__(self, x): | |
| noise = torch.rand(x.size(0), self.num_patches, device=x.device) | |
| argsort = torch.argsort(noise, dim=1) | |
| return argsort < self.num_mask | |