(result, filter=0)
| 37 | |
| 38 | |
| 39 | def format_results(result, filter=0): |
| 40 | annotations = [] |
| 41 | n = len(result.masks.data) |
| 42 | for i in range(n): |
| 43 | annotation = {} |
| 44 | mask = result.masks.data[i] == 1.0 |
| 45 | |
| 46 | if torch.sum(mask) < filter: |
| 47 | continue |
| 48 | annotation["id"] = i |
| 49 | annotation["segmentation"] = mask.cpu().numpy() |
| 50 | annotation["bbox"] = result.boxes.data[i] |
| 51 | annotation["score"] = result.boxes.conf[i] |
| 52 | annotation["area"] = annotation["segmentation"].sum() |
| 53 | annotations.append(annotation) |
| 54 | return annotations |
| 55 | |
| 56 | |
| 57 | def filter_masks(annotations): # filter the overlap mask |
no outgoing calls
no test coverage detected