MCPcopy
hub / github.com/hustvl/Vim / make_dataset_dicts

Function make_dataset_dicts

det/tests/data/test_coco.py:45–74  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

43
44
45def 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
77class TestRLEToJson(unittest.TestCase):

Callers 1

testMethod · 0.85

Calls 2

uncompressed_rleFunction · 0.85
maxMethod · 0.80

Tested by

no test coverage detected