Load result file and return a result api object. :param resFile (str) : file name of result file :return: res (obj) : result api object
(self, resFile)
| 176 | self.cats = cats |
| 177 | |
| 178 | def loadRes(self, resFile): |
| 179 | """ |
| 180 | Load result file and return a result api object. |
| 181 | :param resFile (str) : file name of result file |
| 182 | :return: res (obj) : result api object |
| 183 | """ |
| 184 | res = adapter() |
| 185 | res.dataset['images'] = [img for img in self.dataset['images']] |
| 186 | |
| 187 | print('Loading and preparing results...') |
| 188 | tic = time.time() |
| 189 | if type(resFile) == str or (PYTHON_VERSION == 2 and type(resFile) == unicode): |
| 190 | nms = [] |
| 191 | with open(resFile, 'r') as f: |
| 192 | line = f.readline().strip('\n') |
| 193 | # print("Hello2") |
| 194 | while line: |
| 195 | nms.append(line) |
| 196 | line = f.readline().strip('\n') |
| 197 | dataset, anns, cats, imgs = {}, {}, {}, {} |
| 198 | cnt = 0 |
| 199 | for file in nms: |
| 200 | contents = json.load(open("./results/" + file, 'r')) |
| 201 | if cnt == 0: |
| 202 | # print(contents) |
| 203 | cnt = cnt + 1 |
| 204 | imgid = int(file.split('/')[1].split('.')[0]) |
| 205 | # print(imgid) |
| 206 | |
| 207 | for idx, item in enumerate(contents['results']): |
| 208 | |
| 209 | ## anns |
| 210 | annid = int(str(imgid) + str(idx)) |
| 211 | bbox = [item['x'],item['y'],item['width'],item['height']] |
| 212 | levelid = item['id'] |
| 213 | cartype = item['type'] |
| 214 | |
| 215 | ann = {} |
| 216 | ann['id'] = annid |
| 217 | ann['bbox'] = bbox |
| 218 | ann['levelid'] = levelid |
| 219 | ann['cartype'] = cartype |
| 220 | ann['image_id'] = imgid |
| 221 | ann['iscrowd'] = 0 |
| 222 | ann['score'] = item['score'] |
| 223 | anns[ann['id']] = ann |
| 224 | |
| 225 | anns = list(anns.values()) |
| 226 | assert type(anns) == list, 'results in not an array of objects' |
| 227 | # print(anns) |
| 228 | annsImgIds = [ann['image_id'] for ann in anns] |
| 229 | # print(len(annsImgIds)) |
| 230 | assert set(annsImgIds) == (set(annsImgIds) & set(list(self.imgs.keys()))), \ |
| 231 | 'Results do not correspond to current coco set' |
| 232 | if 'bbox' in anns[0] and not anns[0]['bbox'] == []: |
| 233 | # res.dataset['categories'] = copy.deepcopy(self.dataset['categories']) |
| 234 | for id, ann in enumerate(anns): |
| 235 | bb = ann['bbox'] |
no test coverage detected