Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. import json
  2. import pandas as pd
  3. from pathlib import Path
  4.  
  5. coco_json = Path('./jsons/test_public.json')
  6. pred_json = Path('./results/out.pkl.json')
  7.  
  8. img_names = dict()
  9. with coco_json.open() as f:
  10.     for img_ann in json.load(f)['images']:
  11.         img_names[img_ann['id']] = img_ann['file_name']
  12. with pred_json.open() as f:
  13.     preds = json.load(f)
  14.  
  15. results = []
  16. for pred in preds:
  17.     filename = img_names[pred['image_id']]
  18.     x, y, w, h = pred['bbox']
  19.    
  20.     results.append({
  21.         'image_filename': filename,
  22.         'label_id': pred['category_id'] + 1,
  23.         'x': x,
  24.         'y': y,
  25.         'w': w,
  26.         'h': h,
  27.         'confidence': pred['score'],
  28.     })
  29.  
  30. df = pd.DataFrame(results)
  31. df.to_csv('./results/out.csv', index=False,
  32.     columns=['image_filename', 'label_id', 'x', 'y', 'w', 'h', 'confidence'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement