| import torch |
| from functools import partial |
| from six.moves import map, zip |
| import torch.nn.functional as F |
| import warnings |
|
|
|
|
| def resize(input, |
| size=None, |
| scale_factor=None, |
| mode='nearest', |
| align_corners=None, |
| warning=True): |
| if warning: |
| if size is not None and align_corners: |
| input_h, input_w = tuple(int(x) for x in input.shape[2:]) |
| output_h, output_w = tuple(int(x) for x in size) |
| if output_h > input_h or output_w > output_h: |
| if ((output_h > 1 and output_w > 1 and input_h > 1 |
| and input_w > 1) and (output_h - 1) % (input_h - 1) |
| and (output_w - 1) % (input_w - 1)): |
| warnings.warn( |
| f'When align_corners={align_corners}, ' |
| 'the output would more aligned if ' |
| f'input size {(input_h, input_w)} is `x+1` and ' |
| f'out size {(output_h, output_w)} is `nx+1`') |
| return F.interpolate(input, size, scale_factor, mode, align_corners) |
|
|
|
|
| @torch.no_grad() |
| def compute_mask_IoU(masks, target): |
| temp = masks * target |
| intersection = temp.sum(dim=-1) |
| union = ((masks + target) - temp).sum(dim=-1) |
| return intersection / (union + 1e-12) |
|
|