Ejemplo n.º 1
0
 def __init__(self):
     self.d = Dataset('full_pascal_trainval')
     self.d_val = Dataset('full_pascal_test')
     self.cls = 'dog'
     suffix = 'default'
     self.csc = CSCClassifier(suffix, self.cls, self.d, self.d_val)
     csc_test = np.load(config.get_ext_dets_filename(self.d, 'csc_default'))
     self.dets = csc_test[()]
Ejemplo n.º 2
0
 def __init__(self):
   self.d = Dataset('full_pascal_trainval')
   self.d_val = Dataset('full_pascal_test')
   self.cls = 'dog'
   suffix = 'default'
   self.csc = CSCClassifier(suffix, self.cls, self.d, self.d_val)
   csc_test = np.load(config.get_ext_dets_filename(self.d, 'csc_default'))
   self.dets = csc_test[()]
Ejemplo n.º 3
0
 def load_ext_detections(cls,dataset,suffix,force=False):
   """
   Loads multi-image, multi-class array of detections for all images in the
   given dataset.
   Loads from canonical cache location.
   """
   t = time.time()
   filename = config.get_ext_dets_filename(dataset, suffix)
   # check for cached full file
   if os.path.exists(filename) and not force:
     all_dets_table = np.load(filename)[()]
   else:
     # TODO also return times, or process them to add to dets?
     all_dets = []
     for i in range(comm_rank,len(dataset.images),comm_size):
       image = dataset.images[i]
       if re.search('dpm',suffix):
         # NOTE: not actually using the given suffix in the call below
         dets = cls.load_dpm_dets_for_image(image,dataset)
         ind_vector = np.ones((np.shape(dets)[0],1)) * i
         dets = np.hstack((dets,ind_vector))
         cols = ['x','y','w','h','dummy','dummy','dummy','dummy','score','time','cls_ind','img_ind']
         good_ind = [0,1,2,3,8,9,10,11]
         dets = dets[:,good_ind]
       elif re.search('csc',suffix):
         # NOTE: not actually using the given suffix in the call below
         dets = cls.load_csc_dpm_dets_for_image(image,dataset)
         ind_vector = np.ones((np.shape(dets)[0],1)) * i
         dets = np.hstack((dets,ind_vector))
       elif re.search('ctf',suffix):
         # Split the suffix into ctf and the main part
         actual_suffix = suffix.split('_')[1]
         dets = cls.load_ctf_dets_for_image(image, dataset, actual_suffix)
         ind_vector = np.ones((np.shape(dets)[0],1)) * i
         dets = np.hstack((dets,ind_vector))
       else:
         print(suffix)
         raise RuntimeError('Unknown detector type in suffix')
       all_dets.append(dets)
     final_dets = None
     if comm_rank==0:
       final_dets = []
     safebarrier(comm)
     final_dets = comm.reduce(all_dets,op=MPI.SUM,root=0)
     all_dets_table = None
     if comm_rank == 0:
       all_dets_table = Table()
       all_dets_table.name = suffix
       all_dets_table.cols = ['x', 'y', 'w', 'h', 'score', 'time', 'cls_ind', 'img_ind']
       all_dets_table.arr = np.vstack(final_dets)
       np.save(filename,all_dets_table)
       print("Found %d dets"%all_dets_table.shape[0])
     all_dets_table = comm.bcast(all_dets_table,root=0)
   time_elapsed = time.time()-t
   print("DatasetPolicy.load_ext_detections took %.3f"%time_elapsed)
   return all_dets_table
Ejemplo n.º 4
0
 def load_ext_detections(cls, dataset, suffix, force=False):
     """
 Loads multi-image, multi-class array of detections for all images in the
 given dataset.
 Loads from canonical cache location.
 """
     t = time.time()
     filename = config.get_ext_dets_filename(dataset, suffix)
     # check for cached full file
     if os.path.exists(filename) and not force:
         all_dets_table = np.load(filename)[()]
     else:
         # TODO also return times, or process them to add to dets?
         all_dets = []
         for i in range(comm_rank, len(dataset.images), comm_size):
             image = dataset.images[i]
             if re.search('dpm', suffix):
                 # NOTE: not actually using the given suffix in the call below
                 dets = cls.load_dpm_dets_for_image(image, dataset)
                 ind_vector = np.ones((np.shape(dets)[0], 1)) * i
                 dets = np.hstack((dets, ind_vector))
                 cols = [
                     'x', 'y', 'w', 'h', 'dummy', 'dummy', 'dummy', 'dummy',
                     'score', 'time', 'cls_ind', 'img_ind'
                 ]
                 good_ind = [0, 1, 2, 3, 8, 9, 10, 11]
                 dets = dets[:, good_ind]
             elif re.search('csc', suffix):
                 # NOTE: not actually using the given suffix in the call below
                 dets = cls.load_csc_dpm_dets_for_image(image, dataset)
                 ind_vector = np.ones((np.shape(dets)[0], 1)) * i
                 dets = np.hstack((dets, ind_vector))
             elif re.search('ctf', suffix):
                 # Split the suffix into ctf and the main part
                 actual_suffix = suffix.split('_')[1]
                 dets = cls.load_ctf_dets_for_image(image, dataset,
                                                    actual_suffix)
                 ind_vector = np.ones((np.shape(dets)[0], 1)) * i
                 dets = np.hstack((dets, ind_vector))
             else:
                 print(suffix)
                 raise RuntimeError('Unknown detector type in suffix')
             all_dets.append(dets)
         final_dets = None
         if comm_rank == 0:
             final_dets = []
         safebarrier(comm)
         final_dets = comm.reduce(all_dets, op=MPI.SUM, root=0)
         all_dets_table = None
         if comm_rank == 0:
             all_dets_table = Table()
             all_dets_table.name = suffix
             all_dets_table.cols = [
                 'x', 'y', 'w', 'h', 'score', 'time', 'cls_ind', 'img_ind'
             ]
             all_dets_table.arr = np.vstack(final_dets)
             np.save(filename, all_dets_table)
             print("Found %d dets" % all_dets_table.shape[0])
         all_dets_table = comm.bcast(all_dets_table, root=0)
     time_elapsed = time.time() - t
     print("DatasetPolicy.load_ext_detections took %.3f" % time_elapsed)
     return all_dets_table
Ejemplo n.º 5
0
from common_imports import *
from common_mpi import *
import synthetic.config as config

from synthetic.dataset import Dataset

from synthetic.classifier import Classifier

if __name__=='__main__':
  
  train_set = 'full_pascal_train'
  train_dataset = Dataset(train_set)  
  images = train_dataset.images
  classes = config.pascal_classes
  suffix = 'default'
  filename = config.get_ext_dets_filename(train_dataset, 'csc_'+suffix)
  csc_train = np.load(filename)
  csc_train = csc_train[()]  
  csc_train = csc_train.subset(['score', 'cls_ind', 'img_ind'])
  score = csc_train.subset(['score']).arr
  classif = Classifier()
  csc_train.arr = classif.normalize_dpm_scores(csc_train.arr)

  numpos = train_dataset.get_ground_truth().shape[0]
  
  threshs = np.arange(0,1.01,0.05)
  
  result_filename = config.res_dir + 'thresh_classify.txt'
  
  
  result_file = open(result_filename, 'a')
Ejemplo n.º 6
0
from common_imports import *
from common_mpi import *
import synthetic.config as config

from synthetic.dataset import Dataset

from synthetic.classifier import Classifier

if __name__ == '__main__':

    train_set = 'full_pascal_train'
    train_dataset = Dataset(train_set)
    images = train_dataset.images
    classes = config.pascal_classes
    suffix = 'default'
    filename = config.get_ext_dets_filename(train_dataset, 'csc_' + suffix)
    csc_train = np.load(filename)
    csc_train = csc_train[()]
    csc_train = csc_train.subset(['score', 'cls_ind', 'img_ind'])
    score = csc_train.subset(['score']).arr
    classif = Classifier()
    csc_train.arr = classif.normalize_dpm_scores(csc_train.arr)

    numpos = train_dataset.get_ground_truth().shape[0]

    threshs = np.arange(0, 1.01, 0.05)

    result_filename = config.res_dir + 'thresh_classify.txt'

    result_file = open(result_filename, 'a')
    threshs = np.array([0.15])