def _get_atom_features(self, fextractor_type): if self.feature_dict[fextractor_type] == 'all': fextractor_class = FeatureExtractor.find_subclass(fextractor_type) atom_features = fextractor_class.ATOM_FEATURES + getattr(fextractor_class, 'DERIVED_ATOM_FEATURES', []) else: atom_features = self.feature_dict[fextractor_type] return atom_features
def _get_fextractor_instance(self, fextractor_type): fextractor_class = FeatureExtractor.find_subclass(fextractor_type) fextractor = fextractor_class(assets=self.assets, logger=self.logger, fifo_mode=self.fifo_mode, delete_workdir=self.delete_workdir, result_store=self.result_store, optional_dict=self.optional_dict, optional_dict2=self.optional_dict2, ) return fextractor
def run(self): """ Do all the calculation here. :return: """ # for each FeatureExtractor_type key in feature_dict, find the subclass # of FeatureExtractor, run, and put results in a dict for fextractor_type in self.feature_dict: fextractor_class = FeatureExtractor.find_subclass(fextractor_type) if self.feature_option_dict is not None \ and fextractor_type in self.feature_option_dict: optional_dict = self.feature_option_dict[fextractor_type] else: optional_dict = self.optional_dict # FIXME: hacky runner = fextractor_class( self.assets, logger=None, fifo_mode=self.fifo_mode, delete_workdir=self.delete_workdir, result_store=self.result_store, optional_dict=optional_dict, optional_dict2=self.optional_dict2, ) runner.run(parallelize=self.parallelize, processes=self.processes) results = runner.results self.type2results_dict[fextractor_type] = results # assemble an output dict with demanded atom features # atom_features_dict = self.fextractor_atom_features_dict result_dicts = list(map(lambda x: dict(), self.assets)) for fextractor_type in self.feature_dict: assert fextractor_type in self.type2results_dict for atom_feature in self._get_atom_features(fextractor_type): scores_key = self._get_scores_key(fextractor_type, atom_feature) for result_index, result in enumerate( self.type2results_dict[fextractor_type]): try: result_dicts[result_index][scores_key] = result[ scores_key] except KeyError: scores_key_alt = BasicResult.scores_key_wildcard_match( result.result_dict, scores_key) result_dicts[result_index][scores_key] = result[ scores_key_alt] self.results = list( map(lambda tasset: BasicResult(tasset[0], tasset[1]), zip(self.assets, result_dicts)))
def run(self): """ Do all the calculation here. :return: """ # for each FeatureExtractor_type key in feature_dict, find the subclass # of FeatureExtractor, run, and put results in a dict for fextractor_type in self.feature_dict: # fextractor = self._get_fextractor_instance(fextractor_type) # fextractor.run() # results = fextractor.results fextractor_class = FeatureExtractor.find_subclass(fextractor_type) runner = fextractor_class( self.assets, logger=None, fifo_mode=self.fifo_mode, delete_workdir=self.delete_workdir, result_store=self.result_store, optional_dict=self.optional_dict, optional_dict2=self.optional_dict2, ) runner.run(parallelize=self.parallelize) results = runner.results self.type2results_dict[fextractor_type] = results # assemble an output dict with demanded atom features # atom_features_dict = self.fextractor_atom_features_dict result_dicts = map(lambda x: dict(), self.assets) for fextractor_type in self.feature_dict: assert fextractor_type in self.type2results_dict for atom_feature in self._get_atom_features(fextractor_type): scores_key = self._get_scores_key(fextractor_type, atom_feature) for result_index, result in enumerate( self.type2results_dict[fextractor_type]): result_dicts[result_index][scores_key] = result[scores_key] self.results = map( lambda (asset, result_dict): BasicResult(asset, result_dict), zip(self.assets, result_dicts))
def run(self): """ Do all the calculation here. :return: """ # for each FeatureExtractor_type key in feature_dict, find the subclass # of FeatureExtractor, run, and put results in a dict for fextractor_type in self.feature_dict: # fextractor = self._get_fextractor_instance(fextractor_type) # fextractor.run() # results = fextractor.results fextractor_class = FeatureExtractor.find_subclass(fextractor_type) runner = fextractor_class( self.assets, logger=None, fifo_mode=self.fifo_mode, delete_workdir=self.delete_workdir, result_store=self.result_store, optional_dict=self.optional_dict, optional_dict2=self.optional_dict2, ) runner.run(parallelize=self.parallelize) results = runner.results self.type2results_dict[fextractor_type] = results # assemble an output dict with demanded atom features # atom_features_dict = self.fextractor_atom_features_dict result_dicts = map(lambda x: dict(), self.assets) for fextractor_type in self.feature_dict: assert fextractor_type in self.type2results_dict for atom_feature in self._get_atom_features(fextractor_type): scores_key = self._get_scores_key(fextractor_type, atom_feature) for result_index, result in enumerate(self.type2results_dict[fextractor_type]): result_dicts[result_index][scores_key] = result[scores_key] self.results = map( lambda (asset, result_dict): BasicResult(asset, result_dict), zip(self.assets, result_dicts) )
def _get_fextractor_instance(self, fextractor_type): fextractor_class = FeatureExtractor.find_subclass(fextractor_type) if self.feature_option_dict is not None \ and fextractor_type in self.feature_option_dict: optional_dict = self.feature_option_dict[fextractor_type] else: optional_dict = self.optional_dict # FIXME: hacky fextractor = fextractor_class( assets=self.assets, logger=self.logger, fifo_mode=self.fifo_mode, delete_workdir=self.delete_workdir, result_store=self.result_store, optional_dict=optional_dict, optional_dict2=self.optional_dict2, ) return fextractor
def test_get_fextractor_subclasses(self): fextractor_subclasses = FeatureExtractor.get_subclasses_recursively() self.assertTrue(VmafFeatureExtractor in fextractor_subclasses) self.assertTrue(MomentFeatureExtractor in fextractor_subclasses)
def _get_scores_key(self, fextractor_type, atom_feature): fextractor_subclass = FeatureExtractor.find_subclass(fextractor_type) scores_key = fextractor_subclass.get_scores_key(atom_feature) return scores_key