我们从Python开源项目中,提取了以下30个代码示例,用于说明如何使用datasets.nthu()。
def evaluate_detections_one_file(self, all_boxes, output_dir): # open results file filename = os.path.join(output_dir, 'detections.txt') print 'Writing all nthu results to file ' + filename with open(filename, 'wt') as f: # for each image for im_ind, index in enumerate(self.image_index): # for each class for cls_ind, cls in enumerate(self.classes): if cls == '__background__': continue dets = all_boxes[cls_ind][im_ind] if dets == []: continue 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' f.write('{:s} {:s} {:f} {:f} {:f} {:f} {:d} {:f}\n'.format(\ index, cls, dets[k, 0], dets[k, 1], dets[k, 2], dets[k, 3], subcls, dets[k, 4]))
def evaluate_proposals(self, all_boxes, output_dir): # for each image for im_ind, index in enumerate(self.image_index): filename = os.path.join(output_dir, index + '.txt') print 'Writing nthu results to file ' + filename with open(filename, 'wt') as f: # for each class for cls_ind, cls in enumerate(self.classes): if cls == '__background__': continue dets = all_boxes[cls_ind][im_ind] if dets == []: continue for k in xrange(dets.shape[0]): f.write('{:f} {:f} {:f} {:f} {:.32f}\n'.format(\ dets[k, 0], dets[k, 1], dets[k, 2], dets[k, 3], dets[k, 4]))
def _get_default_path(self): """ Return the default path where nthu is expected to be installed. """ return os.path.join(datasets.ROOT_DIR, 'data', 'NTHU')
def evaluate_detections(self, all_boxes, output_dir): # load the mapping for subcalss the alpha (viewpoint) filename = os.path.join(self._nthu_path, '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[3]) # for each image for im_ind, index in enumerate(self.image_index): filename = os.path.join(output_dir, index + '.txt') print 'Writing nthu results to file ' + filename with open(filename, 'wt') as f: # for each class for cls_ind, cls in enumerate(self.classes): if cls == '__background__': continue dets = all_boxes[cls_ind][im_ind] if dets == []: continue 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' alpha = mapping[subcls] f.write('{:s} -1 -1 {:f} {:f} {:f} {:f} {:f} -1 -1 -1 -1 -1 -1 -1 {:.32f}\n'.format(\ cls, alpha, dets[k, 0], dets[k, 1], dets[k, 2], dets[k, 3], dets[k, 4])) # write detection results into one file
def evaluate_proposals_msr(self, all_boxes, output_dir): # for each image for im_ind, index in enumerate(self.image_index): filename = os.path.join(output_dir, index + '.txt') print 'Writing nthu results to file ' + filename with open(filename, 'wt') as f: dets = all_boxes[im_ind] if dets == []: continue for k in xrange(dets.shape[0]): f.write('{:f} {:f} {:f} {:f} {:.32f}\n'.format(dets[k, 0], dets[k, 1], dets[k, 2], dets[k, 3], dets[k, 4]))