scalar_map: (1, h, w, C) is the feature map of a single image.
(
scalar_map: torch.Tensor,
img_size,
interpolation="nearest",
)
| 629 | |
| 630 | |
| 631 | def get_scale_map( |
| 632 | scalar_map: torch.Tensor, |
| 633 | img_size, |
| 634 | interpolation="nearest", |
| 635 | ): |
| 636 | """ |
| 637 | scalar_map: (1, h, w, C) is the feature map of a single image. |
| 638 | """ |
| 639 | if scalar_map.shape[0] != 1: |
| 640 | scalar_map = scalar_map[None] |
| 641 | scalar_map = (scalar_map - scalar_map.min()) / ( |
| 642 | scalar_map.max() - scalar_map.min() + 1e-6 |
| 643 | ) |
| 644 | scalar_map = F.interpolate( |
| 645 | scalar_map.permute(0, 3, 1, 2), |
| 646 | size=img_size, |
| 647 | mode=interpolation, |
| 648 | ).permute(0, 2, 3, 1) |
| 649 | # cmap = plt.get_cmap("viridis") |
| 650 | # scalar_map = cmap(scalar_map)[..., :3] |
| 651 | # make it 3 channels |
| 652 | scalar_map = torch.cat([scalar_map] * 3, dim=-1) |
| 653 | scalar_map = scalar_map.cpu().numpy().squeeze(0) |
| 654 | return scalar_map |
| 655 | |
| 656 | |
| 657 | def create_image_grid_with_annotations(images, annotations, font=cv2.FONT_HERSHEY_SIMPLEX, font_scale=1, font_color=(255, 255, 255), thickness=2): |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…