Exemplo n.º 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 = 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 = os.path.join(
            train_dataset.config.get_dets_configs_dir(train_dataset),
            detname + '.txt')
        if os.path.exists(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)
Exemplo n.º 2
0
    def __init__(self,
                 config,
                 test_dataset,
                 train_dataset,
                 weights_dataset_name=None,
                 **kwargs):
        """
        Initialize the DatasetPolicy, getting it ready to run on the whole dataset
        or a single image.
        - test, train, weights datasets should be:
            - val,    train,        val:        for training the weights
            - test, trainval, val:        for final run
        - **kwargs update the default config
        """
        self.config = config

        # TODO: get rid of doing it this way, be explicit every time
        policy_config = copy.copy(DatasetPolicy.default_config)
        policy_config.update(kwargs)

        self.dataset = test_dataset
        self.train_dataset = train_dataset
        if not weights_dataset_name:
            weights_dataset_name = self.dataset.name
        self.weights_dataset_name = weights_dataset_name

        self.__dict__.update(policy_config)
        print("DatasetPolicy running with:")
        pprint(self.__dict__)
        self.ev = Evaluation(self.config, self)
        self.tt = TicToc()

        # Determine inference mode:
        # fixed_order, random, oracle policy modes get fixed_order inference
        # mode
        if re.search('fastinf', self.policy_mode):
            self.inference_mode = 'fastinf'
        elif self.policy_mode == 'random':
            self.inference_mode = 'random'
        elif self.policy_mode in ['no_smooth', 'backoff']:
            self.inference_mode = self.policy_mode
        else:
            self.inference_mode = 'fixed_order'

        # Determine fastinf model name
        self.fastinf_model_name = 'this_is_empty'
        if self.inference_mode == 'fastinf':
            if self.detectors == ['csc_default']:
                self.fastinf_model_name = 'CSC'
            elif self.detectors == ['perfect']:
                self.fastinf_model_name = 'perfect'
            elif self.detectors == ['gist']:
                self.fastinf_model_name = 'GIST'
            elif self.detectors == ['gist', 'csc_default']:
                self.fastinf_model_name = 'GIST_CSC'
            else:
                raise RuntimeError("""
                    We don't have Fastinf models for the detector combination you
                    are running with: %s""" % self.detectors)

        # load the actions and the corresponding weights and we're ready to go
        self.test_actions = self.init_actions()
        self.actions = self.test_actions
        self.load_weights()