(self, img)
| 154 | self.ratio = ratio |
| 155 | |
| 156 | def __call__(self, img): |
| 157 | h, w = img.shape[-2:] |
| 158 | |
| 159 | d = np.random.randint(self.d1, self.d2) |
| 160 | l = int(d * self.ratio + 0.5) |
| 161 | |
| 162 | mask = np.ones((h, w), np.float32) |
| 163 | st_h = np.random.randint(d) |
| 164 | st_w = np.random.randint(d) |
| 165 | |
| 166 | for i in range(h // d + 1): |
| 167 | s_h = d * i + st_h |
| 168 | t_h = min(s_h + l, h) |
| 169 | for j in range(w // d + 1): |
| 170 | s_w = d * j + st_w |
| 171 | t_w = min(s_w + l, w) |
| 172 | mask[s_h:t_h, s_w:t_w] = 0 |
| 173 | |
| 174 | mask = torch.from_numpy(mask).to(img.device) |
| 175 | img = img * mask |
| 176 | |
| 177 | return img |
| 178 | |
| 179 | class RandomErasing: |
| 180 | def __init__(self, probability: float = 0.5, sl: float = 0.02, sh: float = 0.4, r1: float = 0.3): |
nothing calls this directly
no outgoing calls
no test coverage detected