Skip to content

Instantly share code, notes, and snippets.

@kalaspuffar
Last active June 10, 2018 06:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kalaspuffar/24f8f08d5627224a2e002bdddc0fc960 to your computer and use it in GitHub Desktop.
Save kalaspuffar/24f8f08d5627224a2e002bdddc0fc960 to your computer and use it in GitHub Desktop.
def _load_simple_annotation(self, index):
"""
Load image and bounding boxes info from txt space separeted values where you have
lines in the format of
classification x1 y1 x2 y2
"""
filename = os.path.join(self._data_path, 'Annotations', index + '.txt')
# print 'Loading: {}'.format(filename)
with open(filename) as f:
lines = [l.split() for l in f if l]
num_objs = len(lines)
boxes = np.zeros((num_objs, 4), dtype=np.uint16)
gt_classes = np.zeros((num_objs), dtype=np.int32)
overlaps = np.zeros((num_objs, self.num_classes), dtype=np.float32)
# "Seg" area here is just the box area
seg_areas = np.zeros((num_objs), dtype=np.float32)
# Load object bounding boxes into a data frame.
for ix, line in enumerate(lines):
# Make pixel indexes 0-based
x1 = float(line[1])
y1 = float(line[2])
x2 = float(line[3])
y2 = float(line[4])
classification = int(line[0])
boxes[ix, :] = [x1, y1, x2, y2]
gt_classes[ix] = classification
overlaps[ix, classification] = 1.0
eg_areas[ix] = (x2 - x1 + 1) * (y2 - y1 + 1)
overlaps = scipy.sparse.csr_matrix(overlaps)
return {'boxes' : boxes,
'gt_classes': gt_classes,
'gt_overlaps' : overlaps,
'flipped' : False}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment