forked from dbolya/yolact
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsave_bboxes.py
More file actions
33 lines (22 loc) · 797 Bytes
/
save_bboxes.py
File metadata and controls
33 lines (22 loc) · 797 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
""" This script transforms and saves bbox coordinates into a pickle object for easy loading. """
import os.path as osp
import json, pickle
import sys
import numpy as np
COCO_ROOT = osp.join('.', 'data/coco/')
annotation_file = 'instances_train2017.json'
annotation_path = osp.join(COCO_ROOT, 'annotations/', annotation_file)
dump_file = 'weights/bboxes.pkl'
with open(annotation_path, 'r') as f:
annotations_json = json.load(f)
annotations = annotations_json['annotations']
images = annotations_json['images']
images = {image['id']: image for image in images}
bboxes = []
for ann in annotations:
image = images[ann['image_id']]
w,h = (image['width'], image['height'])
if 'bbox' in ann:
bboxes.append([w, h] + ann['bbox'])
with open(dump_file, 'wb') as f:
pickle.dump(bboxes, f)