Download faceforge_core/utils.py from ArchCoder/faceforge: direct link, hf CLI and curl.
- Browser
- Download file 1.11 kB
-
https://huggingface.co/spaces/ArchCoder/faceforge/resolve/afb8be0dd7b2ca5f5f714ccf1fd73e413e87a638/faceforge_core/utils.py
- Command line
-
hf download hf://spaces/ArchCoder/faceforge@afb8be0dd7b2ca5f5f714ccf1fd73e413e87a638/faceforge_core/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/ArchCoder/faceforge/resolve/afb8be0dd7b2ca5f5f714ccf1fd73e413e87a638/faceforge_core/utils.py
1.11 kB
| import random | |
| import math | |
| import torch | |
| def random_circle_init(min_r : float = 0.5, on_edge : bool = False): | |
| theta = random.uniform(0, 2 * math.pi) | |
| if on_edge: | |
| r = 1.0 | |
| else: | |
| r = random.uniform(min_r, 1.0) | |
| x = r * math.cos(theta) | |
| y = r * math.sin(theta) | |
| return x, y | |
| def recursive_find_dtype(x): | |
| """ | |
| Assuming x is some list/tuple of things that could be tensors, searches for any tensors and returns dtype | |
| """ | |
| for i in x: | |
| if isinstance(i, list): | |
| res = recursive_find_dtype(i) | |
| if res is None: | |
| continue | |
| else: | |
| return res | |
| elif isinstance(i, torch.Tensor): | |
| return i.dtype | |
| def recursive_find_device(x): | |
| """ | |
| Assuming x is some list/tuple of things that could be tensors, searches for any tensors and returns device | |
| """ | |
| for i in x: | |
| if isinstance(i, list): | |
| res = recursive_find_device(i) | |
| if res is None: | |
| continue | |
| return res | |
| elif isinstance(i, torch.Tensor): | |
| return i.device | |