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: runner = self._get_fextractor_instance(fextractor_type) 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 _post_process_result(cls, result): result = super(VmafFeatureExtractor, cls)._post_process_result(result) # adm2 = # (adm_num + ADM2_CONSTANT) / (adm_den + ADM2_CONSTANT) adm2_scores_key = cls.get_scores_key('adm2') adm_num_scores_key = BasicResult.scores_key_wildcard_match( result.result_dict, cls.get_scores_key('adm_num')) adm_den_scores_key = BasicResult.scores_key_wildcard_match( result.result_dict, cls.get_scores_key('adm_den')) result.result_dict[adm2_scores_key] = list( (np.array(result.result_dict[adm_num_scores_key]) + cls.ADM2_CONSTANT) / (np.array(result.result_dict[adm_den_scores_key]) + cls.ADM2_CONSTANT)) # vif_scalei = vif_num_scalei / vif_den_scalei, i = 0, 1, 2, 3 vif_num_scale0_scores_key = BasicResult.scores_key_wildcard_match( result.result_dict, cls.get_scores_key('vif_num_scale0')) vif_den_scale0_scores_key = BasicResult.scores_key_wildcard_match( result.result_dict, cls.get_scores_key('vif_den_scale0')) vif_num_scale1_scores_key = BasicResult.scores_key_wildcard_match( result.result_dict, cls.get_scores_key('vif_num_scale1')) vif_den_scale1_scores_key = BasicResult.scores_key_wildcard_match( result.result_dict, cls.get_scores_key('vif_den_scale1')) vif_num_scale2_scores_key = BasicResult.scores_key_wildcard_match( result.result_dict, cls.get_scores_key('vif_num_scale2')) vif_den_scale2_scores_key = BasicResult.scores_key_wildcard_match( result.result_dict, cls.get_scores_key('vif_den_scale2')) vif_num_scale3_scores_key = BasicResult.scores_key_wildcard_match( result.result_dict, cls.get_scores_key('vif_num_scale3')) vif_den_scale3_scores_key = BasicResult.scores_key_wildcard_match( result.result_dict, cls.get_scores_key('vif_den_scale3')) vif_scale0_scores_key = cls.get_scores_key('vif_scale0') vif_scale1_scores_key = cls.get_scores_key('vif_scale1') vif_scale2_scores_key = cls.get_scores_key('vif_scale2') vif_scale3_scores_key = cls.get_scores_key('vif_scale3') result.result_dict[vif_scale0_scores_key] = list( (np.array(result.result_dict[vif_num_scale0_scores_key]) / np.array(result.result_dict[vif_den_scale0_scores_key]))) result.result_dict[vif_scale1_scores_key] = list( (np.array(result.result_dict[vif_num_scale1_scores_key]) / np.array(result.result_dict[vif_den_scale1_scores_key]))) result.result_dict[vif_scale2_scores_key] = list( (np.array(result.result_dict[vif_num_scale2_scores_key]) / np.array(result.result_dict[vif_den_scale2_scores_key]))) result.result_dict[vif_scale3_scores_key] = list( (np.array(result.result_dict[vif_num_scale3_scores_key]) / np.array(result.result_dict[vif_den_scale3_scores_key]))) # vif2 = # ((vif_num_scale0 / vif_den_scale0) + (vif_num_scale1 / vif_den_scale1) + # (vif_num_scale2 / vif_den_scale2) + (vif_num_scale3 / vif_den_scale3)) / 4.0 vif_scores_key = cls.get_scores_key('vif2') result.result_dict[vif_scores_key] = list( ((np.array(result.result_dict[vif_num_scale0_scores_key]) / np.array(result.result_dict[vif_den_scale0_scores_key])) + (np.array(result.result_dict[vif_num_scale1_scores_key]) / np.array(result.result_dict[vif_den_scale1_scores_key])) + (np.array(result.result_dict[vif_num_scale2_scores_key]) / np.array(result.result_dict[vif_den_scale2_scores_key])) + (np.array(result.result_dict[vif_num_scale3_scores_key]) / np.array(result.result_dict[vif_den_scale3_scores_key]))) / 4.0) # adm_scalei = adm_num_scalei / adm_den_scalei, i = 0, 1, 2, 3 adm_num_scale0_scores_key = BasicResult.scores_key_wildcard_match( result.result_dict, cls.get_scores_key('adm_num_scale0')) adm_den_scale0_scores_key = BasicResult.scores_key_wildcard_match( result.result_dict, cls.get_scores_key('adm_den_scale0')) adm_num_scale1_scores_key = BasicResult.scores_key_wildcard_match( result.result_dict, cls.get_scores_key('adm_num_scale1')) adm_den_scale1_scores_key = BasicResult.scores_key_wildcard_match( result.result_dict, cls.get_scores_key('adm_den_scale1')) adm_num_scale2_scores_key = BasicResult.scores_key_wildcard_match( result.result_dict, cls.get_scores_key('adm_num_scale2')) adm_den_scale2_scores_key = BasicResult.scores_key_wildcard_match( result.result_dict, cls.get_scores_key('adm_den_scale2')) adm_num_scale3_scores_key = BasicResult.scores_key_wildcard_match( result.result_dict, cls.get_scores_key('adm_num_scale3')) adm_den_scale3_scores_key = BasicResult.scores_key_wildcard_match( result.result_dict, cls.get_scores_key('adm_den_scale3')) adm_scale0_scores_key = cls.get_scores_key('adm_scale0') adm_scale1_scores_key = cls.get_scores_key('adm_scale1') adm_scale2_scores_key = cls.get_scores_key('adm_scale2') adm_scale3_scores_key = cls.get_scores_key('adm_scale3') result.result_dict[adm_scale0_scores_key] = list( (np.array(result.result_dict[adm_num_scale0_scores_key]) + cls.ADM_SCALE_CONSTANT) / (np.array(result.result_dict[adm_den_scale0_scores_key]) + cls.ADM_SCALE_CONSTANT)) result.result_dict[adm_scale1_scores_key] = list( (np.array(result.result_dict[adm_num_scale1_scores_key]) + cls.ADM_SCALE_CONSTANT) / (np.array(result.result_dict[adm_den_scale1_scores_key]) + cls.ADM_SCALE_CONSTANT)) result.result_dict[adm_scale2_scores_key] = list( (np.array(result.result_dict[adm_num_scale2_scores_key]) + cls.ADM_SCALE_CONSTANT) / (np.array(result.result_dict[adm_den_scale2_scores_key]) + cls.ADM_SCALE_CONSTANT)) result.result_dict[adm_scale3_scores_key] = list( (np.array(result.result_dict[adm_num_scale3_scores_key]) + cls.ADM_SCALE_CONSTANT) / (np.array(result.result_dict[adm_den_scale3_scores_key]) + cls.ADM_SCALE_CONSTANT)) # adm3 = \ # (((adm_num_scale0 + ADM_SCALE_CONSTANT) / (adm_den_scale0 + ADM_SCALE_CONSTANT)) # + ((adm_num_scale1 + ADM_SCALE_CONSTANT) / (adm_den_scale1 + ADM_SCALE_CONSTANT)) # + ((adm_num_scale2 + ADM_SCALE_CONSTANT) / (adm_den_scale2 + ADM_SCALE_CONSTANT)) # + ((adm_num_scale3 + ADM_SCALE_CONSTANT) / (adm_den_scale3 + ADM_SCALE_CONSTANT))) / 4.0 adm3_scores_key = cls.get_scores_key('adm3') result.result_dict[adm3_scores_key] = list( (((np.array(result.result_dict[adm_num_scale0_scores_key]) + cls.ADM_SCALE_CONSTANT) / (np.array(result.result_dict[adm_den_scale0_scores_key]) + cls.ADM_SCALE_CONSTANT)) + ((np.array(result.result_dict[adm_num_scale1_scores_key]) + cls.ADM_SCALE_CONSTANT) / (np.array(result.result_dict[adm_den_scale1_scores_key]) + cls.ADM_SCALE_CONSTANT)) + ((np.array(result.result_dict[adm_num_scale2_scores_key]) + cls.ADM_SCALE_CONSTANT) / (np.array(result.result_dict[adm_den_scale2_scores_key]) + cls.ADM_SCALE_CONSTANT)) + ((np.array(result.result_dict[adm_num_scale3_scores_key]) + cls.ADM_SCALE_CONSTANT) / (np.array(result.result_dict[adm_den_scale3_scores_key]) + cls.ADM_SCALE_CONSTANT))) / 4.0) # validate for feature in cls.DERIVED_ATOM_FEATURES: assert cls.get_scores_key(feature) in result.result_dict return result