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)
| 97 | return box |
| 98 | |
| 99 | def 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 |
nothing calls this directly
no outgoing calls
no test coverage detected