MCPcopy Create free account
hub / github.com/NVlabs/RADIO / get_scale_map

Function get_scale_map

examples/visualize_features.py:631–654  ·  view source on GitHub ↗

scalar_map: (1, h, w, C) is the feature map of a single image.

(
    scalar_map: torch.Tensor,
    img_size,
    interpolation="nearest",
)

Source from the content-addressed store, hash-verified

629
630
631def 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
657def create_image_grid_with_annotations(images, annotations, font=cv2.FONT_HERSHEY_SIMPLEX, font_scale=1, font_color=(255, 255, 255), thickness=2):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…