def __init__(self, dataset, train_dataset, cls, dets, detname, rtype, args): ''' Also pass in the region-type as rtype and the according arguments as args ''' ExternalDetector.__init__(self, dataset, train_dataset, cls, dets, detname) self.region_model = RegionModel(rtype, args)
def compute_score(self, image, region_id, oracle=False): """ Return the 0/1 decision of whether the cls of this detector is present in the image, given the detections table for a given region id. If oracle=True, returns the correct answer (look up the ground truth). """ img_ind = self.dataset.get_img_ind(image) dets = self.dets.filter_on_column('img_ind',img_ind,omit=True) self.filter_dets_for_reg_id(image, dets, region_id) # At this position choose only the detections that fall into the desired region return ExternalDetector.compute_score(self, image, oracle, dets) # Now call the regular external detector with just those detections
def detect(self, image, region_id, astable=False): """ Return the detections that match that image index in cached dets for a specific region in the image that is determined by the region_id. Must return in the same format as the Detector superclass, so we have to delete a column. """ img_ind = self.dataset.get_img_ind(image) dets = self.dets.filter_on_column('img_ind',img_ind,omit=True) # This function already creates a copy self.filter_dets_for_reg_id(image, dets, region_id) # At this position choose only the detections that fall into the desired region return ExternalDetector.detect(self, image, astable, dets) # Now call the regular external detector with just those detections
def compute_score(self, image, region_id, oracle=False): """ Return the 0/1 decision of whether the cls of this detector is present in the image, given the detections table for a given region id. If oracle=True, returns the correct answer (look up the ground truth). """ img_ind = self.dataset.get_img_ind(image) dets = self.dets.filter_on_column('img_ind', img_ind, omit=True) self.filter_dets_for_reg_id( image, dets, region_id ) # At this position choose only the detections that fall into the desired region return ExternalDetector.compute_score( self, image, oracle, dets ) # Now call the regular external detector with just those detections
def init_actions(self, train=False): """ Return list of actions, which involves initializing the detectors. If train==True, the external detectors will load trainset detections. """ dataset = self.dataset if train: dataset = self.train_dataset actions = [] for detector in self.detectors: # synthetic perfect detector if detector == 'perfect': for cls in dataset.classes: det = PerfectDetector(dataset, self.train_dataset, cls) actions.append(ImageAction('%s_%s' % (detector, cls), det)) # GIST classifier elif detector == 'gist': # Make a single action that runs all the GIST classifiers dets = [] for cls in self.dataset.classes: gist_table = np.load( config.get_gist_dict_filename(self.dataset)) dets.append( GistClassifier(cls, self.train_dataset, gist_table, self.dataset)) gist_all = GistForAllClasses(dets) actions.append(ImageAction('gist', gist_all)) # real detectors, with pre-cached detections elif detector in ['dpm', 'csc_default', 'csc_half']: # load the dets from cache file and parcel out to classes all_dets = self.load_ext_detections(dataset, detector) for cls in dataset.classes: cls_ind = dataset.get_ind(cls) all_dets_for_cls = all_dets.filter_on_column('cls_ind', cls_ind, omit=True) det = ExternalDetector(dataset, self.train_dataset, cls, all_dets_for_cls, detector) actions.append(ImageAction('%s_%s' % (detector, cls), det)) else: raise RuntimeError("Unknown mode in detectors: %s" % self.detectors) return actions
def detect(self, image, region_id, astable=False): """ Return the detections that match that image index in cached dets for a specific region in the image that is determined by the region_id. Must return in the same format as the Detector superclass, so we have to delete a column. """ img_ind = self.dataset.get_img_ind(image) dets = self.dets.filter_on_column( 'img_ind', img_ind, omit=True) # This function already creates a copy self.filter_dets_for_reg_id( image, dets, region_id ) # At this position choose only the detections that fall into the desired region return ExternalDetector.detect( self, image, astable, dets ) # Now call the regular external detector with just those detections