MCPcopy Create free account
hub / github.com/UX-Decoder/Semantic-SAM / sem_seg_postprocess

Function sem_seg_postprocess

semantic_sam/modules/postprocessing.py:99–122  ·  view source on GitHub ↗

Return semantic segmentation predictions in the original resolution. The input images are often resized when entering semantic segmentor. Moreover, in same cases, they also padded inside segmentor to be divisible by maximum network stride. As a result, we often need the predictions

(result, img_size, output_height, output_width)

Source from the content-addressed store, hash-verified

97 return box
98
99def sem_seg_postprocess(result, img_size, output_height, output_width):
100 """
101 Return semantic segmentation predictions in the original resolution.
102
103 The input images are often resized when entering semantic segmentor. Moreover, in same
104 cases, they also padded inside segmentor to be divisible by maximum network stride.
105 As a result, we often need the predictions of the segmentor in a different
106 resolution from its inputs.
107
108 Args:
109 result (Tensor): semantic segmentation prediction logits. A tensor of shape (C, H, W),
110 where C is the number of classes, and H, W are the height and width of the prediction.
111 img_size (tuple): image size that segmentor is taking as input.
112 output_height, output_width: the desired output resolution.
113
114 Returns:
115 semantic segmentation prediction (Tensor): A tensor of the shape
116 (C, output_height, output_width) that contains per-pixel soft predictions.
117 """
118 result = result[:, : img_size[0], : img_size[1]].expand(1, -1, -1, -1)
119 result = F.interpolate(
120 result, size=(output_height, output_width), mode="bicubic", align_corners=False, antialias=True
121 )[0]
122 return result

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected