()
| 154 | |
| 155 | |
| 156 | def benchmark_paste(): |
| 157 | S = 800 |
| 158 | H, W = image_shape = (S, S) |
| 159 | N = 64 |
| 160 | torch.manual_seed(42) |
| 161 | masks = torch.rand(N, 28, 28) |
| 162 | |
| 163 | center = torch.rand(N, 2) * 600 + 100 |
| 164 | wh = torch.clamp(torch.randn(N, 2) * 40 + 200, min=50) |
| 165 | x0y0 = torch.clamp(center - wh * 0.5, min=0.0) |
| 166 | x1y1 = torch.clamp(center + wh * 0.5, max=S) |
| 167 | boxes = Boxes(torch.cat([x0y0, x1y1], axis=1)) |
| 168 | |
| 169 | def func(device, n=3): |
| 170 | m = masks.to(device=device) |
| 171 | b = boxes.to(device=device) |
| 172 | |
| 173 | def bench(): |
| 174 | for _ in range(n): |
| 175 | paste_masks_in_image(m, b, image_shape) |
| 176 | if device.type == "cuda": |
| 177 | torch.cuda.synchronize() |
| 178 | |
| 179 | return bench |
| 180 | |
| 181 | specs = [{"device": torch.device("cpu"), "n": 3}] |
| 182 | if torch.cuda.is_available(): |
| 183 | specs.append({"device": torch.device("cuda"), "n": 3}) |
| 184 | |
| 185 | benchmark(func, "paste_masks", specs, num_iters=10, warmup_iters=2) |
| 186 | |
| 187 | |
| 188 | if __name__ == "__main__": |
no test coverage detected