コード例 #1
0
    def __init__(self,
                 dataset,
                 train_dataset,
                 cls,
                 detname='perfect',
                 detector_config=None):
        self.dataset = dataset
        self.train_dataset = train_dataset
        self.cls = cls
        self.cls_ind = dataset.get_ind(cls)
        self.detname = detname
        self.tt = ut.TicToc()

        # Check if configs exist and look up the correct config for this detname and cls
        # TODO: this is inefficient because this file is re-opened for every class
        loaded_detector_config = None
        fname = opjoin(config.get_dets_configs_dir(train_dataset),
                       detname + '.txt')
        if opexists(fname):
            with open(fname) as f:
                configs = json.load(f)
            config_name = detname + '_' + cls
            if config_name in configs:
                loaded_detector_config = configs[config_name]
        self.config = loaded_detector_config
        if not self.config:
            self.config = Detector.DEFAULT_CONFIG
        if detector_config:
            self.config.update(detector_config)
コード例 #2
0
  def output_det_statistics(self):
    """
    Collect samples and display the statistics of times and naive and
    actual_ap increases for each class, on the train dataset.
    """
    det_configs = {}
    all_dets,all_clses,all_samples = self.run_on_dataset(train=True,force=True)
    if comm_rank==0:
      cols = ['action_ind','dt','det_naive_ap','det_actual_ap','img_ind']
      sample_array = np.array([[getattr(s,col) for s in all_samples] for col in cols]).T
      table = Table(sample_array,cols)

      # go through actions
      for ind,action in enumerate(self.actions):
        st = table.filter_on_column('action_ind', ind)
        means = np.mean(st.arr[:,1:],0)
        det_configs[self.actions[ind].name] = {}
        # TODO: should depend on image size
        det_configs[self.actions[ind].name]['avg_time'] = means[0]
        det_configs[self.actions[ind].name]['naive_ap'] = means[1]
        det_configs[self.actions[ind].name]['actual_ap'] = means[2]
        if isinstance(action.obj,Detector):
          img_inds = st.subset_arr('img_ind').astype(int)
          cls_ind = action.obj.cls_ind
          d = self.train_dataset
          presence_inds = np.array([d.images[img_ind].contains_cls_ind(cls_ind) for img_ind in img_inds])
          st_present = np.atleast_2d(st.arr[np.flatnonzero(presence_inds),:])
          if st_present.shape[0]>0:
            means = np.mean(st_present[:,2:],0)
            det_configs[self.actions[ind].name]['naive_ap|present'] = means[0]
            det_configs[self.actions[ind].name]['actual_ap|present'] = means[1]
          else:
            # this is just for testing, where there may not be enough dets
            det_configs[self.actions[ind].name]['naive_ap|present'] = 0
            det_configs[self.actions[ind].name]['actual_ap|present'] = 0
          st_absent = np.atleast_2d(st.arr[np.flatnonzero(presence_inds==False),:])
          if st_absent.shape[0]>0:
            means = np.mean(st_absent[:,2:],0)
            # naive_ap|absent is always 0
            det_configs[self.actions[ind].name]['actual_ap|absent'] = means[1]
          else:
            det_configs[self.actions[ind].name]['actual_ap|absent'] = 0
      detectors = '-'.join(self.detectors)
      filename = opjoin(
        config.get_dets_configs_dir(self.train_dataset), detectors+'.txt')
      with open(filename,'w') as f:
        json.dump(det_configs,f)
    safebarrier(comm)
    det_configs = comm.bcast(det_configs,root=0)
    return det_configs
コード例 #3
0
  def __init__(self, dataset, train_dataset, cls, detname='perfect', detector_config=None):
    self.dataset = dataset
    self.train_dataset = train_dataset
    self.cls = cls
    self.cls_ind = dataset.get_ind(cls)
    self.detname = detname
    self.tt = ut.TicToc()

    # Check if configs exist and look up the correct config for this detname and cls
    # TODO: this is inefficient because this file is re-opened for every class
    loaded_detector_config = None 
    fname = opjoin(config.get_dets_configs_dir(train_dataset),detname+'.txt')
    if opexists(fname):
      with open(fname) as f:
        configs = json.load(f)
      config_name = detname+'_'+cls
      if config_name in configs:
        loaded_detector_config = configs[config_name]
    self.config = loaded_detector_config
    if not self.config:
      self.config = Detector.DEFAULT_CONFIG
    if detector_config:
      self.config.update(detector_config)
コード例 #4
0
ファイル: dataset_policy.py プロジェクト: raldam/timely
    def output_det_statistics(self):
        """
    Collect samples and display the statistics of times and naive and
    actual_ap increases for each class, on the train dataset.
    """
        det_configs = {}
        all_dets, all_clses, all_samples = self.run_on_dataset(train=True,
                                                               force=True)
        if comm_rank == 0:
            cols = [
                'action_ind', 'dt', 'det_naive_ap', 'det_actual_ap', 'img_ind'
            ]
            sample_array = np.array([[getattr(s, col) for s in all_samples]
                                     for col in cols]).T
            table = Table(sample_array, cols)

            # go through actions
            for ind, action in enumerate(self.actions):
                st = table.filter_on_column('action_ind', ind)
                means = np.mean(st.arr[:, 1:], 0)
                det_configs[self.actions[ind].name] = {}
                # TODO: should depend on image size
                det_configs[self.actions[ind].name]['avg_time'] = means[0]
                det_configs[self.actions[ind].name]['naive_ap'] = means[1]
                det_configs[self.actions[ind].name]['actual_ap'] = means[2]
                if isinstance(action.obj, Detector):
                    img_inds = st.subset_arr('img_ind').astype(int)
                    cls_ind = action.obj.cls_ind
                    d = self.train_dataset
                    presence_inds = np.array([
                        d.images[img_ind].contains_cls_ind(cls_ind)
                        for img_ind in img_inds
                    ])
                    st_present = np.atleast_2d(
                        st.arr[np.flatnonzero(presence_inds), :])
                    if st_present.shape[0] > 0:
                        means = np.mean(st_present[:, 2:], 0)
                        det_configs[self.actions[ind].
                                    name]['naive_ap|present'] = means[0]
                        det_configs[self.actions[ind].
                                    name]['actual_ap|present'] = means[1]
                    else:
                        # this is just for testing, where there may not be enough dets
                        det_configs[
                            self.actions[ind].name]['naive_ap|present'] = 0
                        det_configs[
                            self.actions[ind].name]['actual_ap|present'] = 0
                    st_absent = np.atleast_2d(
                        st.arr[np.flatnonzero(presence_inds == False), :])
                    if st_absent.shape[0] > 0:
                        means = np.mean(st_absent[:, 2:], 0)
                        # naive_ap|absent is always 0
                        det_configs[self.actions[ind].
                                    name]['actual_ap|absent'] = means[1]
                    else:
                        det_configs[
                            self.actions[ind].name]['actual_ap|absent'] = 0
            detectors = '-'.join(self.detectors)
            filename = opjoin(config.get_dets_configs_dir(self.train_dataset),
                              detectors + '.txt')
            with open(filename, 'w') as f:
                json.dump(det_configs, f)
        safebarrier(comm)
        det_configs = comm.bcast(det_configs, root=0)
        return det_configs