Download src/efficientvit/apps/data_provider/augment/bbox.py from Takuhin/OMG: direct link, hf CLI and curl.
- Browser
- Download file 786 Bytes
-
https://huggingface.co/spaces/Takuhin/OMG/resolve/main/src/efficientvit/apps/data_provider/augment/bbox.py
- Command line
-
hf download hf://spaces/Takuhin/OMG/src/efficientvit/apps/data_provider/augment/bbox.py
-
curl -L -o bbox.py https://huggingface.co/spaces/Takuhin/OMG/resolve/main/src/efficientvit/apps/data_provider/augment/bbox.py
786 Bytes
| # EfficientViT: Multi-Scale Linear Attention for High-Resolution Dense Prediction | |
| # Han Cai, Junyan Li, Muyan Hu, Chuang Gan, Song Han | |
| # International Conference on Computer Vision (ICCV), 2023 | |
| import numpy as np | |
| __all__ = ["rand_bbox"] | |
| def rand_bbox( | |
| h: int, | |
| w: int, | |
| lam: float, | |
| rand_func: callable = np.random.uniform, | |
| ) -> tuple[int, int, int, int]: | |
| """randomly sample bbox, used in cutmix""" | |
| cut_rat = np.sqrt(1.0 - lam) | |
| cut_w = w * cut_rat | |
| cut_h = h * cut_rat | |
| # uniform | |
| cx = rand_func(0, w) | |
| cy = rand_func(0, h) | |
| bbx1 = int(np.clip(cx - cut_w / 2, 0, w)) | |
| bby1 = int(np.clip(cy - cut_h / 2, 0, h)) | |
| bbx2 = int(np.clip(cx + cut_w / 2, 0, w)) | |
| bby2 = int(np.clip(cy + cut_h / 2, 0, h)) | |
| return bbx1, bby1, bbx2, bby2 | |