Spaces:
Runtime error
Runtime error
Download khandy/boxes/boxes_utils.py from cabrel09/insect-detection: direct link, hf CLI and curl.
- Browser
- Download file 657 Bytes
-
https://huggingface.co/spaces/cabrel09/insect-detection/resolve/main/khandy/boxes/boxes_utils.py
- Command line
-
hf download hf://spaces/cabrel09/insect-detection/khandy/boxes/boxes_utils.py
-
curl -L -o boxes_utils.py https://huggingface.co/spaces/cabrel09/insect-detection/resolve/main/khandy/boxes/boxes_utils.py
657 Bytes
| import numpy as np | |
| def assert_and_normalize_shape(x, length): | |
| """ | |
| Args: | |
| x: ndarray | |
| length: int | |
| """ | |
| if x.ndim == 0: | |
| return x | |
| elif x.ndim == 1: | |
| if len(x) == 1: | |
| return x | |
| elif len(x) == length: | |
| return x | |
| else: | |
| raise ValueError('Incompatible shape!') | |
| elif x.ndim == 2: | |
| if x.shape == (1, 1): | |
| return np.squeeze(x, axis=-1) | |
| elif x.shape == (length, 1): | |
| return np.squeeze(x, axis=-1) | |
| else: | |
| raise ValueError('Incompatible shape!') | |
| else: | |
| raise ValueError('Incompatible ndim!') | |