def evaluate_detections(self, all_boxes, output_dir):
# load the mapping for subcalss the azimuth (viewpoint)
filename = os.path.join(self._pascal3d_path, cfg.SUBCLS_NAME, 'mapping.txt')
assert os.path.exists(filename), \
'Path does not exist: {}'.format(filename)
mapping = np.zeros(self._num_subclasses, dtype=np.float)
with open(filename) as f:
for line in f:
words = line.split()
subcls = int(words[0])
mapping[subcls] = float(words[2])
for cls_ind, cls in enumerate(self.classes):
if cls == '__background__':
continue
print 'Writing {} VOC results file'.format(cls)
filename = os.path.join(output_dir, 'det_' + self._image_set + '_' + cls + '.txt')
print filename
with open(filename, 'wt') as f:
for im_ind, index in enumerate(self.image_index):
dets = all_boxes[cls_ind][im_ind]
if dets == []:
continue
# the VOCdevkit expects 1-based indices
for k in xrange(dets.shape[0]):
subcls = int(dets[k, 5])
cls_name = self.classes[self.subclass_mapping[subcls]]
assert (cls_name == cls), 'subclass not in class'
azimuth = mapping[subcls]
f.write('{:s} {:.3f} {:.3f} {:.1f} {:.1f} {:.1f} {:.1f}\n'.
format(index, dets[k, 4], azimuth,
dets[k, 0] + 1, dets[k, 1] + 1,
dets[k, 2] + 1, dets[k, 3] + 1))
# evaluate detection results
评论列表
文章目录