Spaces:
Running on Zero
Running on Zero
Download submodules/RoMa/romatch/utils/kde.py from CompVis/EDGS: direct link, hf CLI and curl.
- Browser
- Download file 404 Bytes
-
https://huggingface.co/spaces/CompVis/EDGS/resolve/refs%2Fpr%2F5/submodules/RoMa/romatch/utils/kde.py
- Command line
-
hf download hf://spaces/CompVis/EDGS@refs/pr/5/submodules/RoMa/romatch/utils/kde.py
-
curl -L -o kde.py https://huggingface.co/spaces/CompVis/EDGS/resolve/refs%2Fpr%2F5/submodules/RoMa/romatch/utils/kde.py
404 Bytes
| import torch | |
| def kde(x, std = 0.1, half = True, down = None): | |
| # use a gaussian kernel to estimate density | |
| if half: | |
| x = x.half() # Do it in half precision TODO: remove hardcoding | |
| if down is not None: | |
| scores = (-torch.cdist(x,x[::down])**2/(2*std**2)).exp() | |
| else: | |
| scores = (-torch.cdist(x,x)**2/(2*std**2)).exp() | |
| density = scores.sum(dim=-1) | |
| return density |