MCPcopy
hub / github.com/dbolya/yolact / dump_web

Method dump_web

eval.py:342–371  ·  view source on GitHub ↗

Dumps it in the format for my web app. Warning: bad code ahead!

(self)

Source from the content-addressed store, hash-verified

340 json.dump(data, f)
341
342 def dump_web(self):
343 """ Dumps it in the format for my web app. Warning: bad code ahead! """
344 config_outs = ['preserve_aspect_ratio', 'use_prediction_module',
345 'use_yolo_regressors', 'use_prediction_matching',
346 'train_masks']
347
348 output = {
349 'info' : {
350 'Config': {key: getattr(cfg, key) for key in config_outs},
351 }
352 }
353
354 image_ids = list(set([x['image_id'] for x in self.bbox_data]))
355 image_ids.sort()
356 image_lookup = {_id: idx for idx, _id in enumerate(image_ids)}
357
358 output['images'] = [{'image_id': image_id, 'dets': []} for image_id in image_ids]
359
360 # These should already be sorted by score with the way prep_metrics works.
361 for bbox, mask in zip(self.bbox_data, self.mask_data):
362 image_obj = output['images'][image_lookup[bbox['image_id']]]
363 image_obj['dets'].append({
364 'score': bbox['score'],
365 'bbox': bbox['bbox'],
366 'category': cfg.dataset.class_names[get_transformed_cat(bbox['category_id'])],
367 'mask': mask['segmentation'],
368 })
369
370 with open(os.path.join(args.web_det_path, '%s.json' % cfg.name), 'w') as f:
371 json.dump(output, f)
372
373
374

Callers 1

evaluateFunction · 0.95

Calls 3

get_transformed_catFunction · 0.85
appendMethod · 0.80
dumpMethod · 0.80

Tested by

no test coverage detected