Download src/training/utils.py from lyhisme/DenseVLM: direct link, hf CLI and curl.
- Browser
- Download file 943 Bytes
-
https://huggingface.co/lyhisme/DenseVLM/resolve/refs%2Fpr%2F1/src/training/utils.py
- Command line
-
hf download hf://lyhisme/DenseVLM@refs/pr/1/src/training/utils.py
-
curl -L -o utils.py https://huggingface.co/lyhisme/DenseVLM/resolve/refs%2Fpr%2F1/src/training/utils.py
943 Bytes
| import numpy as np | |
| from functools import partial | |
| from six.moves import map, zip | |
| def multi_apply(func, *args, **kwargs): | |
| """Apply function to a list of arguments. | |
| Note: | |
| This function applies the ``func`` to multiple inputs and | |
| map the multiple outputs of the ``func`` into different | |
| list. Each list contains the same type of outputs corresponding | |
| to different inputs. | |
| Args: | |
| func (Function): A function that will be applied to a list of | |
| arguments | |
| Returns: | |
| tuple(list): A tuple containing multiple list, each list contains \ | |
| a kind of returned results by the function | |
| """ | |
| pfunc = partial(func, **kwargs) if kwargs else func | |
| map_results = map(pfunc, *args) | |
| return tuple(map(list, zip(*map_results))) | |
| def mask2box(mask): | |
| ys, xs = np.where(mask) | |
| y0, y1 = ys.min(), ys.max() | |
| x0, x1 = xs.min(), xs.max() | |
| return x0, y0, x1, y1 | |