MCPcopy Create free account
hub / github.com/OpenDriveLab/OpenLane / createIndex

Method createIndex

eval/CIPO_evaluation/adapter.py:92–145  ·  view source on GitHub ↗
(self, files)

Source from the content-addressed store, hash-verified

90 # self.dataset = dataset
91 # self.createIndex()
92 def createIndex(self, files):
93 print('creating index...')
94 dataset, anns, cats, imgs = {}, {}, {}, {}
95 imgToAnns,catToImgs = defaultdict(list),defaultdict(list)
96 cnt = 0
97 for file in files:
98 contents = json.load(open("./annotations/" + file, 'r'))
99 if cnt == 0:
100 # print(contents)
101 cnt = cnt + 1
102 imgid = int(file.split('/')[1].split('.')[0])
103 # print(imgid)
104
105 ## imgs
106 img = {}
107 img['id'] = int(imgid)
108 img['file_path'] = contents['raw_file_path']
109 imgs[img['id']] = img
110
111 for idx, item in enumerate(contents['results']):
112
113 ## anns
114 annid = int(str(imgid)+ str(idx))
115 bbox = [item['x'],item['y'],item['width'],item['height']]
116 levelid = item['id']
117 cartype = item['type']
118
119 ann = {}
120 ann['id'] = annid
121 ann['bbox'] = bbox
122 ann['levelid'] = levelid
123 ann['cartype'] = cartype
124 ann['image_id'] = imgid
125 ann['iscrowd'] = 0
126 bb = ann['bbox']
127 x1, x2, y1, y2 = [bb[0], bb[0]+bb[2], bb[1], bb[1]+bb[3]]
128 if not 'segmentation' in ann:
129 ann['segmentation'] = [[x1, y1, x1, y2, x2, y2, x2, y1]]
130 if not 'area' in ann:
131 ann['area'] = bb[2]*bb[3]
132
133 imgToAnns[ann['image_id']].append(ann)
134 anns[ann['id']] = ann
135 dataset['images'] = list(imgs.values())
136 dataset['annotations'] = list(anns.values())
137
138 print('index created!')
139 # create class members
140 self.dataset = dataset
141 self.anns = anns
142 self.imgToAnns = imgToAnns
143 self.catToImgs = catToImgs
144 self.imgs = imgs
145 self.cats = cats
146
147 def createIndexforResults(self):
148 # create index

Callers 2

__init__Method · 0.95
loadResMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected