Returns a list of dicts that represents a single COCO data point for object detection. The single instance given by `mask` is represented by RLE, either compressed or uncompressed.
(mask, compressed: bool = True)
| 43 | |
| 44 | |
| 45 | def make_dataset_dicts(mask, compressed: bool = True): |
| 46 | """ |
| 47 | Returns a list of dicts that represents a single COCO data point for |
| 48 | object detection. The single instance given by `mask` is represented by |
| 49 | RLE, either compressed or uncompressed. |
| 50 | """ |
| 51 | record = {} |
| 52 | record["file_name"] = "test" |
| 53 | record["image_id"] = 0 |
| 54 | record["height"] = mask.shape[0] |
| 55 | record["width"] = mask.shape[1] |
| 56 | |
| 57 | y, x = np.nonzero(mask) |
| 58 | if compressed: |
| 59 | segmentation = mask_util.encode(np.asarray(mask, order="F")) |
| 60 | else: |
| 61 | segmentation = uncompressed_rle(mask) |
| 62 | min_x = np.min(x) |
| 63 | max_x = np.max(x) |
| 64 | min_y = np.min(y) |
| 65 | max_y = np.max(y) |
| 66 | obj = { |
| 67 | "bbox": [min_x, min_y, max_x, max_y], |
| 68 | "bbox_mode": BoxMode.XYXY_ABS, |
| 69 | "category_id": 0, |
| 70 | "iscrowd": 0, |
| 71 | "segmentation": segmentation, |
| 72 | } |
| 73 | record["annotations"] = [obj] |
| 74 | return [record] |
| 75 | |
| 76 | |
| 77 | class TestRLEToJson(unittest.TestCase): |
no test coverage detected