-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathread_data.py
43 lines (34 loc) · 1.54 KB
/
read_data.py
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
34
35
36
37
38
39
40
41
42
43
import json
class GroundTruth:
"""
this class loads the ground truth
"""
def __init__(self, config):
self._objects_all = [] # positive bboxes across images
self.config = config
self.annotations_file = config['data']['annotations_file']
self.images = config['data']['images']
def update_objects_all(self, dictObj):
self._objects_all.append(dictObj)
def load_json(self):
with open(self.annotations_file) as f:
data = json.load(f)
for key in data:
objects_per_image = list()
dictObj = dict()
dictObj['filename'] = self.images + data[key]['filename']
regions = data[key]['regions']
for region in regions:
readObject = dict()
readObject['name'] = 'car'
readObject['xmin'] = float(region['shape_attributes']['x'])
readObject['ymin'] = float(region['shape_attributes']['y'])
readObject['xmax'] = float(region['shape_attributes']['x']) + float(region['shape_attributes']['width'])
readObject['ymax'] = float(region['shape_attributes']['y']) + float(region['shape_attributes']['height'])
objects_per_image.append(readObject)
dictObj['object'] = objects_per_image
dictObj['width'] = self.config['data']['images_width']
dictObj['height'] = self.config['data']['images_height']
self.update_objects_all(dictObj)
def objects_all(self):
return self._objects_all