Spaces:
Runtime error
Runtime error
Download ldm/data/util.py from georgefen/Face-Landmark-ControlNet: direct link, hf CLI and curl.
- Browser
- Download file 629 Bytes
-
https://huggingface.co/spaces/georgefen/Face-Landmark-ControlNet/resolve/71b2c26a9cf87a1705b400126fdc3eee4d71f6e9/ldm/data/util.py
- Command line
-
hf download hf://spaces/georgefen/Face-Landmark-ControlNet@71b2c26a9cf87a1705b400126fdc3eee4d71f6e9/ldm/data/util.py
-
curl -L -o util.py https://huggingface.co/spaces/georgefen/Face-Landmark-ControlNet/resolve/71b2c26a9cf87a1705b400126fdc3eee4d71f6e9/ldm/data/util.py
629 Bytes
| import torch | |
| from ldm.modules.midas.api import load_midas_transform | |
| class AddMiDaS(object): | |
| def __init__(self, model_type): | |
| super().__init__() | |
| self.transform = load_midas_transform(model_type) | |
| def pt2np(self, x): | |
| x = ((x + 1.0) * .5).detach().cpu().numpy() | |
| return x | |
| def np2pt(self, x): | |
| x = torch.from_numpy(x) * 2 - 1. | |
| return x | |
| def __call__(self, sample): | |
| # sample['jpg'] is tensor hwc in [-1, 1] at this point | |
| x = self.pt2np(sample['jpg']) | |
| x = self.transform({"image": x})["image"] | |
| sample['midas_in'] = x | |
| return sample |