def test_run_vmaf_both_local_explain_and_ci(self): exe = VmafConfig.root_path('python', 'vmaf', 'script', 'run_vmaf.py') line = 'yuv420p 576 324 {root}/python/test/resource/yuv/src01_hrc00_576x324.yuv ' \ '{root}/python/test/resource/yuv/src01_hrc01_576x324.yuv'.format(root=VmafConfig.root_path()) cmd = "{exe} {line} --local-explain --ci >/dev/null 2>&1".format(line=line, exe=exe) ret = subprocess.call(cmd, shell=True) self.assertEqual(ret, 2)
def test_run_ffmpeg2vmaf_ci(self): exe = VmafConfig.root_path('ffmpeg2vmaf') line = '576 324 {root}/python/test/resource/mp4/Seeking_30_480_1050.mp4 ' \ '{root}/python/test/resource/mp4/Seeking_10_288_375.mp4'.format(root=VmafConfig.root_path()) cmd = "{exe} {line} --ci >/dev/null 2>&1".format(line=line, exe=exe) ret = run_process(cmd, shell=True) self.assertEquals(ret, 0)
def test_run_psnr(self): exe = VmafConfig.root_path('run_psnr') line = 'yuv420p 576 324 {root}/python/test/resource/yuv/src01_hrc00_576x324.yuv ' \ '{root}/python/test/resource/yuv/src01_hrc01_576x324.yuv'.format(root=VmafConfig.root_path()) cmd = "{exe} {line} >/dev/null 2>&1".format(line=line, exe=exe) ret = run_process(cmd, shell=True) self.assertEquals(ret, 0)
def test_run_ffmpeg2vmaf_ci_and_local_explain(self): exe = VmafConfig.root_path('ffmpeg2vmaf') line = '576 324 {root}/python/test/resource/mp4/Seeking_30_480_1050.mp4 ' \ '{root}/python/test/resource/mp4/Seeking_10_288_375.mp4'.format(root=VmafConfig.root_path()) cmd = "{exe} {line} --ci --local-explain >/dev/null 2>&1".format(line=line, exe=exe) ret = subprocess.call(cmd, shell=True) self.assertEqual(ret, 2)
def test_run_vmaf(self): exe = VmafConfig.root_path('run_vmaf') line = 'yuv420p 576 324 {root}/python/test/resource/yuv/src01_hrc00_576x324.yuv ' \ '{root}/python/test/resource/yuv/src01_hrc01_576x324.yuv'.format(root=VmafConfig.root_path()) cmd = "{exe} {line} >/dev/null 2>&1".format(line=line, exe=exe) ret = run_process(cmd, shell=True) self.assertEquals(ret, 0)
def test_run_cleaning_cache_psnr(self): exe = VmafConfig.root_path('run_testing') cmd = "{exe} PSNR {dataset} --parallelize --cache-result --suppress-plot".format( exe=exe, dataset=self.dataset_filename) ret = run_process(cmd, shell=True) self.assertEquals(ret, 0) exe = VmafConfig.root_path('python', 'script', 'run_cleaning_cache.py') cmd = "{exe} PSNR {dataset}".format( exe=exe, dataset=self.dataset_filename) ret = run_process(cmd, shell=True) self.assertEquals(ret, 0)
def test_run_cleaning_cache_psnr(self): exe = VmafConfig.root_path('run_testing') cmd = "{exe} PSNR {dataset} --parallelize --cache-result --suppress-plot".format( exe=exe, dataset=self.dataset_filename) ret = run_process(cmd, shell=True) self.assertEquals(ret, 0) exe = VmafConfig.root_path('python', 'script', 'run_cleaning_cache.py') cmd = "{exe} PSNR {dataset}".format(exe=exe, dataset=self.dataset_filename) ret = run_process(cmd, shell=True) self.assertEquals(ret, 0)
def test_run_vmaf_in_batch(self): line = 'yuv420p 576 324 {root}/python/test/resource/yuv/src01_hrc00_576x324.yuv ' \ '{root}/python/test/resource/yuv/src01_hrc01_576x324.yuv'.format(root=VmafConfig.root_path()) cmd = 'echo "{line}" > {batch_filename}'.format( line=line, batch_filename=self.batch_filename) ret = run_process(cmd, shell=True) self.assertEquals(ret, 0) exe = VmafConfig.root_path('run_vmaf_in_batch') cmd = "{exe} {input} --parallelize >/dev/null 2>&1".format( exe=exe, input=self.batch_filename) ret = run_process(cmd, shell=True) self.assertEquals(ret, 0)
def test_run_vmaf_in_batch_ci(self): line = 'yuv420p 576 324 {root}/python/test/resource/yuv/src01_hrc00_576x324.yuv ' \ '{root}/python/test/resource/yuv/src01_hrc01_576x324.yuv'.format(root=VmafConfig.root_path()) cmd = 'echo "{line}" > {batch_filename}'.format( line=line, batch_filename=self.batch_filename) ret = run_process(cmd, shell=True) self.assertEquals(ret, 0) exe = VmafConfig.root_path('run_vmaf_in_batch') cmd = "{exe} {input} --parallelize --ci >/dev/null 2>&1".format( exe=exe, input=self.batch_filename) ret = run_process(cmd, shell=True) self.assertEquals(ret, 0)
def test_run_testing_vmaf_raw_dataset(self): exe = VmafConfig.root_path('python', 'vmaf', 'script', 'run_testing.py') cmd = "{exe} VMAF {dataset} --parallelize --suppress-plot".format( exe=exe, dataset=self.raw_dataset_filename) ret = run_process(cmd, shell=True) self.assertEqual(ret, 0)
def test_run_vmafossexec_wrong_subsample(self): exe = VmafConfig.root_path('wrapper', 'vmafossexec') cmd = "{exe} yuv420p 576 324 {ref} {dis} {model} --thread 0 --subsample 0".format( exe=exe, ref=VmafConfig.test_resource_path("yuv", "src01_hrc00_576x324.yuv"), dis=VmafConfig.test_resource_path("yuv", "src01_hrc01_576x324.yuv"), model=VmafConfig.model_path("other_models", "vmaf_v0.6.0.pkl")) ret = subprocess.call(cmd, shell=True) self.assertEquals(ret, self.RC_MORE_ARGUMENT_ISSUE)
def test_run_vmafossexec_wrong_model_fmt(self): exe = VmafConfig.root_path('wrapper', 'vmafossexec') cmd = "{exe} yuv420p 576 324 {ref} {dis} {model}".format( exe=exe, ref=VmafConfig.test_resource_path("yuv", "src01_hrc00_576x324.yuv"), dis=VmafConfig.test_resource_path("yuv", "src01_hrc01_576x324.yuv"), model=VmafConfig.model_path("other_models", "vmaf_v0.6.0.pkl.model")) ret = subprocess.call(cmd, shell=True) self.assertEquals(ret, self.RC_LOGIC_ERROR)
def test_run_ffmpeg2vmaf_ci_and_local_explain(self): exe = VmafConfig.root_path('python', 'vmaf', 'script', 'ffmpeg2vmaf.py') line = '576 324 {ref} {dis}'.format(ref=VmafConfig.test_resource_path('mp4', 'Seeking_30_480_1050.mp4'), dis=VmafConfig.test_resource_path('mp4', 'Seeking_10_288_375.mp4')) cmd = "{exe} {line} --ci --local-explain >/dev/null 2>&1".format(line=line, exe=exe) ret = subprocess.call(cmd, shell=True) self.assertEqual(ret, 2)
def test_run_vmaf_training_raw_dataset(self): exe = VmafConfig.root_path('run_vmaf_training') cmd = "{exe} {dataset} {param} {param} {output} --parallelize --suppress-plot".format( exe=exe, dataset=self.raw_dataset_filename, param=self.param_filename, output=self.out_model_filepath) ret = run_process(cmd, shell=True) self.assertEquals(ret, 0)
def test_run_vmaf_training_processes2_without_parallelize(self): exe = VmafConfig.root_path('python', 'vmaf', 'script', 'run_vmaf_training.py') cmd = "{exe} {dataset} {param} {param} {output} --suppress-plot --processes 2".format( exe=exe, dataset=self.dataset_filename, param=self.param_filename, output=self.out_model_filepath) with self.assertRaises(AssertionError): run_process(cmd, shell=True)
def test_run_vmafossexec_unknown_log_fmt(self): exe = VmafConfig.root_path('src', 'libvmaf', 'vmafossexec') cmd = "{exe} yuv420p 576 324 {ref} {dis} {model} --log-fmt xml_XXX".format( exe=exe, ref=VmafConfig.test_resource_path("yuv", "src01_hrc00_576x324.yuv"), dis=VmafConfig.test_resource_path("yuv", "src01_hrc01_576x324.yuv"), model=VmafConfig.model_path("other_models", "vmaf_v0.6.0.pkl")) ret = subprocess.call(cmd, shell=True) self.assertEquals(ret, self.RC_MORE_ARGUMENT_ISSUE)
def test_run_vmafossexec_nonexist_model_file(self): exe = VmafConfig.root_path('wrapper', 'vmafossexec') cmd = "{exe} yuv420p 576 324 {ref} {dis} {model}".format( exe=exe, ref=VmafConfig.test_resource_path("yuv", "src01_hrc00_576x324.yuv"), dis=VmafConfig.test_resource_path("yuv", "src01_hrc01_576x324.yuv"), model=VmafConfig.model_path("vmaf_v0.6.0.pkl_XXX")) ret = subprocess.call(cmd, shell=True) self.assertEquals(ret, self.RC_VMAF_EXCEPTION)
def test_run_vmafossexec_unknown_pooling(self): exe = VmafConfig.root_path('wrapper', 'vmafossexec') cmd = "{exe} yuv420p 576 324 {ref} {dis} {model} --pool mean_XXX".format( exe=exe, ref=VmafConfig.test_resource_path("yuv", "src01_hrc00_576x324.yuv"), dis=VmafConfig.test_resource_path("yuv", "src01_hrc01_576x324.yuv"), model=VmafConfig.model_path("vmaf_v0.6.0.pkl")) ret = subprocess.call(cmd, shell=True) self.assertEquals(ret, self.RC_MORE_ARGUMENT_ISSUE)
def test_run_vmafossexec(self): exe = VmafConfig.root_path('wrapper', 'vmafossexec') cmd = "{exe} yuv420p 576 324 {ref} {dis} {model} --thread 1 --subsample 2".format( exe=exe, ref=VmafConfig.test_resource_path("yuv", "src01_hrc00_576x324.yuv"), dis=VmafConfig.test_resource_path("yuv", "src01_hrc01_576x324.yuv"), model=VmafConfig.model_path("vmaf_v0.6.0.pkl")) ret = subprocess.call(cmd, shell=True) self.assertEquals(ret, self.RC_SUCCESS)
class StrredFeatureExtractor(MatlabFeatureExtractor): TYPE = 'STRRED_feature' # VERSION = '1.0' # VERSION = '1.1' # fix matlab code where width and height are mistakenly swapped VERSION = '1.2' # fix minor frame and prev frame swap issue ATOM_FEATURES = ['srred', 'trred', ] DERIVED_ATOM_FEATURES = ['strred', ] MATLAB_WORKSPACE = VmafConfig.root_path('matlab', 'strred') @classmethod def _assert_an_asset(cls, asset): super(StrredFeatureExtractor, cls)._assert_an_asset(asset) assert asset.ref_yuv_type == 'yuv420p' and asset.dis_yuv_type == 'yuv420p', \ 'STRRED feature extractor only supports yuv420p for now.' def _generate_result(self, asset): # routine to call the command-line executable and generate quality # scores in the log file. ref_workfile_path = asset.ref_workfile_path dis_workfile_path = asset.dis_workfile_path log_file_path = self._get_log_file_path(asset) current_dir = os.getcwd() + '/' ref_workfile_path = make_absolute_path(ref_workfile_path, current_dir) dis_workfile_path = make_absolute_path(dis_workfile_path, current_dir) log_file_path = make_absolute_path(log_file_path, current_dir) quality_width, quality_height = asset.quality_width_height strred_cmd = '''{matlab} -nodisplay -nosplash -nodesktop -r "run_strred('{ref}', '{dis}', {h}, {w}); exit;" >> {log_file_path}'''.format( matlab=VmafExternalConfig.get_and_assert_matlab(), ref=ref_workfile_path, dis=dis_workfile_path, w=quality_width, h=quality_height, log_file_path=log_file_path, ) if self.logger: self.logger.info(strred_cmd) os.chdir(self.MATLAB_WORKSPACE) run_process(strred_cmd, shell=True) os.chdir(current_dir) @classmethod def _post_process_result(cls, result): # override Executor._post_process_result def _strred(srred_trred): srred, trred = srred_trred try: return srred * trred except TypeError: # possible either srred or trred is None return None result = super(StrredFeatureExtractor, cls)._post_process_result(result) # calculate refvar and disvar from ref1st, ref2nd, dis1st, dis2nd srred_scores_key = cls.get_scores_key('srred') trred_scores_key = cls.get_scores_key('trred') strred_scores_key = cls.get_scores_key('strred') srred_scores = result.result_dict[srred_scores_key] trred_scores = result.result_dict[trred_scores_key] # compute strred scores # === Way One: consistent with VMAF framework, which is to multiply S and T scores per frame, then average # strred_scores = map(_strred, zip(srred_scores, trred_scores)) # === Way Two: authentic way of calculating STRRED score: average first, then multiply === assert len(srred_scores) == len(trred_scores) strred_scores = ListStats.nonemean(srred_scores) * ListStats.nonemean(trred_scores) * np.ones(len(srred_scores)) result.result_dict[strred_scores_key] = strred_scores # validate for feature in cls.DERIVED_ATOM_FEATURES: assert cls.get_scores_key(feature) in result.result_dict return result
class iCIDFeatureExtractor(MatlabFeatureExtractor): TYPE = 'ICID_feature' VERSION = '1.0' ATOM_FEATURES = ['icid'] # DERIVED_ATOM_FEATURES = ['icid_all_same'] MATLAB_WORKSPACE = VmafConfig.root_path('matlab', 'cid_icid') @classmethod def _assert_an_asset(cls, asset): super(iCIDFeatureExtractor, cls)._assert_an_asset(asset) assert asset.ref_yuv_type == asset.dis_yuv_type def _generate_result(self, asset): # routine to call the command-line executable and generate quality # scores in the log file. ref_workfile_path = asset.ref_workfile_path dis_workfile_path = asset.dis_workfile_path log_file_path = self._get_log_file_path(asset) current_dir = os.getcwd() + '/' ref_workfile_path = make_absolute_path(ref_workfile_path, current_dir) dis_workfile_path = make_absolute_path(dis_workfile_path, current_dir) log_file_path = make_absolute_path(log_file_path, current_dir) quality_width, quality_height = asset.quality_width_height icid_cmd = '''{matlab} -nodisplay -nosplash -nodesktop -r "run_icid('{ref}', '{dis}', {h}, {w}, '{yuvtype}'); exit;" >> {log_file_path}'''.format( matlab=VmafExternalConfig.get_and_assert_matlab(), ref=ref_workfile_path, dis=dis_workfile_path, w=quality_width, h=quality_height, yuvtype=asset.ref_yuv_type, log_file_path=log_file_path, ) if self.logger: self.logger.info(icid_cmd) os.chdir(self.MATLAB_WORKSPACE) run_process(icid_cmd, shell=True) os.chdir(current_dir) @classmethod def _post_process_result(cls, result): # override Executor._post_process_result result = super(iCIDFeatureExtractor, cls)._post_process_result(result) # icid_scores_key = cls.get_scores_key('icid') # icid_all_same_scores_key = cls.get_scores_key('icid_all_same') # icid_scores = result.result_dict[icid_scores_key] # result.result_dict[icid_scores_key] = icid_scores # result.result_dict[icid_all_same_scores_key] = icid_scores # # # validate # for feature in cls.DERIVED_ATOM_FEATURES: # assert cls.get_scores_key(feature) in result.result_dict return result
def test_run_testing_psnr(self): exe = VmafConfig.root_path('run_testing') cmd = "{exe} PSNR {dataset} --parallelize --suppress-plot".format( exe=exe, dataset=self.dataset_filename) ret = run_process(cmd, shell=True) self.assertEquals(ret, 0)
# TODO: dependency on libsvm/svmutil needs to be properly done, this is a temporary workaround wrapper from __future__ import absolute_import import sys from vmaf.config import VmafConfig # This will work only when running with a checked out vmaf source, but not via pip install libsvm_path = VmafConfig.root_path('libsvm', 'python') if libsvm_path not in sys.path: # Inject {project}/libsvm/python to PYTHONPATH dynamically sys.path.append(libsvm_path) try: # This import will work only if above injection was meaningful (ie: user has the files in the right place) from svmutil import * # noqa except ImportError as e: print("Can't import svmutil from %s: %s" % (libsvm_path, e)) sys.exit(1)
# TODO: dependency on src/libsvm/svmutil needs to be properly done, this is a temporary workaround wrapper from __future__ import absolute_import import sys from vmaf.config import VmafConfig # This will work only when running with a checked out vmaf source, but not via pip install libsvm_path = VmafConfig.root_path('third_party', 'libsvm', 'python') if libsvm_path not in sys.path: # Inject {project}/src/libsvm/python to PYTHONPATH dynamically sys.path.append(libsvm_path) try: # This import will work only if above injection was meaningful (ie: user has the files in the right place) from svmutil import * # noqa except ImportError as e: print("Can't import svmutil from %s: %s" % (libsvm_path, e)) sys.exit(1)
class STMADFeatureExtractor(MatlabFeatureExtractor): TYPE = "STMAD_feature" VERSION = "0.1" ATOM_FEATURES = ['smad', 'tmad', 'stmad'] DERIVED_ATOM_FEATURES = [ 'smad_all_same', 'tmad_all_same', 'stmad_all_same' ] MATLAB_WORKSPACE = VmafConfig.root_path('matlab', 'STMAD_2011_MatlabCode') # compile necessary functions; need to use mex from within matlab def _custom_init(self): def run_stmad_cmd(stmad_cmd): current_dir = os.getcwd() + '/' os.chdir(self.MATLAB_WORKSPACE) run_process(stmad_cmd, shell=True) os.chdir(current_dir) stmad_mex_cmd_1 = '''{matlab} -nodisplay -nosplash -nodesktop -r "mex ical_std.c; exit;"'''.format( matlab=VmafExternalConfig.get_and_assert_matlab(), ) run_stmad_cmd(stmad_mex_cmd_1) stmad_mex_cmd_2 = '''{matlab} -nodisplay -nosplash -nodesktop -r "mex ical_stat.c; exit;"'''.format( matlab=VmafExternalConfig.get_and_assert_matlab(), ) run_stmad_cmd(stmad_mex_cmd_2) @classmethod def _assert_an_asset(cls, asset): super(STMADFeatureExtractor, cls)._assert_an_asset(asset) assert asset.ref_yuv_type == 'yuv420p' and asset.dis_yuv_type == 'yuv420p', \ 'STMAD feature extractor only supports yuv420p for now.' def _generate_result(self, asset): # routine to call the command-line executable and generate quality # scores in the log file. ref_procfile_path = asset.ref_procfile_path dis_procfile_path = asset.dis_procfile_path log_file_path = self._get_log_file_path(asset) current_dir = os.getcwd() + '/' ref_procfile_path = make_absolute_path(ref_procfile_path, current_dir) dis_procfile_path = make_absolute_path(dis_procfile_path, current_dir) log_file_path = make_absolute_path(log_file_path, current_dir) quality_width, quality_height = asset.quality_width_height stmad_cmd = '''{matlab} -nodisplay -nosplash -nodesktop -r "run_stmad('{ref}', '{dis}', {w}, {h}); exit;" >> {log_file_path}'''.format( matlab=VmafExternalConfig.get_and_assert_matlab(), ref=ref_procfile_path, dis=dis_procfile_path, w=quality_width, h=quality_height, log_file_path=log_file_path, ) if self.logger: self.logger.info(stmad_cmd) os.chdir(self.MATLAB_WORKSPACE) run_process(stmad_cmd, shell=True) os.chdir(current_dir) @classmethod def _post_process_result(cls, result): # override Executor._post_process_result result = super(STMADFeatureExtractor, cls)._post_process_result(result) smad_scores_key = cls.get_scores_key('smad') tmad_scores_key = cls.get_scores_key('tmad') stmad_scores_key = cls.get_scores_key('stmad') smad_all_same_scores_key = cls.get_scores_key('smad_all_same') tmad_all_same_scores_key = cls.get_scores_key('tmad_all_same') stmad_all_same_scores_key = cls.get_scores_key('stmad_all_same') # remember that smad, tmad, stmad are only one value for the whole video so # stmad_all_same_scores is identical to stmad_scores smad_scores = result.result_dict[smad_scores_key] tmad_scores = result.result_dict[tmad_scores_key] stmad_scores = result.result_dict[stmad_scores_key] result.result_dict[smad_scores_key] = smad_scores result.result_dict[tmad_scores_key] = tmad_scores result.result_dict[stmad_scores_key] = stmad_scores result.result_dict[smad_all_same_scores_key] = smad_scores result.result_dict[tmad_all_same_scores_key] = tmad_scores result.result_dict[stmad_all_same_scores_key] = stmad_scores # validate for feature in cls.DERIVED_ATOM_FEATURES: assert cls.get_scores_key(feature) in result.result_dict return result
class SpEEDMatlabFeatureExtractor(MatlabFeatureExtractor): TYPE = 'SpEED_Matlab_feature' VERSION = '0.1' scale_list = [2, 3, 4] ATOM_FEATURES = [] DERIVED_ATOM_FEATURES = [] for scale_now in scale_list: ATOM_FEATURES.append('sspeed_' + str(scale_now)) ATOM_FEATURES.append('tspeed_' + str(scale_now)) DERIVED_ATOM_FEATURES.append('speed_' + str(scale_now)) MATLAB_WORKSPACE = VmafConfig.root_path('matlab', 'SpEED') def _generate_result(self, asset): # routine to call the command-line executable and generate quality # scores in the log file. ref_procfile_path = asset.ref_procfile_path dis_procfile_path = asset.dis_procfile_path log_file_path = self._get_log_file_path(asset) current_dir = os.getcwd() + '/' ref_procfile_path = make_absolute_path(ref_procfile_path, current_dir) dis_procfile_path = make_absolute_path(dis_procfile_path, current_dir) log_file_path = make_absolute_path(log_file_path, current_dir) quality_width, quality_height = asset.quality_width_height speed_cmd = '''{matlab} -nodisplay -nosplash -nodesktop -r "run_speed('{ref}', '{dis}', {w}, {h}, {bands}, '{yuv_type}'); exit;" >> {log_file_path}'''.format( matlab=VmafExternalConfig.get_and_assert_matlab(), ref=ref_procfile_path, dis=dis_procfile_path, w=quality_width, h=quality_height, bands=self.scale_list, yuv_type=self._get_workfile_yuv_type(asset), log_file_path=log_file_path, ) if self.logger: self.logger.info(speed_cmd) os.chdir(self.MATLAB_WORKSPACE) run_process(speed_cmd, shell=True) os.chdir(current_dir) @classmethod def _post_process_result(cls, result): # override Executor._post_process_result def _speed(sspeed_tspeed): sspeed, tspeed = sspeed_tspeed if sspeed is not None and tspeed is not None: return sspeed * tspeed elif sspeed is None: return tspeed elif tspeed is None: return sspeed else: return None result = super(SpEEDMatlabFeatureExtractor, cls)._post_process_result(result) for scale_now in cls.scale_list: sspeed_scale_now_scores_key = cls.get_scores_key('sspeed_' + str(scale_now)) tspeed_scale_now_scores_key = cls.get_scores_key('tspeed_' + str(scale_now)) speed_scale_now_scores_key = cls.get_scores_key('speed_' + str(scale_now)) sspeed_scale_now_scores = result.result_dict[ sspeed_scale_now_scores_key] tspeed_scale_now_scores = result.result_dict[ tspeed_scale_now_scores_key] assert len(sspeed_scale_now_scores) == len(tspeed_scale_now_scores) # consistent with VMAF framework, which is to multiply S and T scores per frame, then average speed_scale_now_scores = list( map(_speed, zip(sspeed_scale_now_scores, tspeed_scale_now_scores))) result.result_dict[ speed_scale_now_scores_key] = speed_scale_now_scores # validate for feature in cls.DERIVED_ATOM_FEATURES: assert cls.get_scores_key(feature) in result.result_dict return result
class StrredOptFeatureExtractor(MatlabFeatureExtractor): TYPE = 'STRREDOpt_feature' VERSION = '1.1' # aligned ST-RREDopt computation, i.e. each current and previous frame for calculation and append to the ST-RREDopt of the first frame the result from the 2nd one ATOM_FEATURES = [ 'srred', 'trred', ] DERIVED_ATOM_FEATURES = ['strred', 'strred_all_same'] MATLAB_WORKSPACE = VmafConfig.root_path('matlab', 'strred') @classmethod def _assert_an_asset(cls, asset): super(StrredOptFeatureExtractor, cls)._assert_an_asset(asset) assert asset.ref_yuv_type == 'yuv420p' and asset.dis_yuv_type == 'yuv420p', \ 'STRRED opt feature extractor only supports yuv420p for now.' def _generate_result(self, asset): # routine to call the command-line executable and generate quality # scores in the log file. ref_procfile_path = asset.ref_procfile_path dis_procfile_path = asset.dis_procfile_path log_file_path = self._get_log_file_path(asset) current_dir = os.getcwd() + '/' ref_procfile_path = make_absolute_path(ref_procfile_path, current_dir) dis_procfile_path = make_absolute_path(dis_procfile_path, current_dir) log_file_path = make_absolute_path(log_file_path, current_dir) quality_width, quality_height = asset.quality_width_height strredopt_cmd = '''{matlab} -nodisplay -nosplash -nodesktop -r "run_strred_opt('{ref}', '{dis}', {w}, {h}); exit;" >> {log_file_path}'''.format( matlab=VmafExternalConfig.get_and_assert_matlab(), ref=ref_procfile_path, dis=dis_procfile_path, w=quality_width, h=quality_height, log_file_path=log_file_path, ) if self.logger: self.logger.info(strredopt_cmd) os.chdir(self.MATLAB_WORKSPACE) run_process(strredopt_cmd, shell=True) os.chdir(current_dir) @classmethod def _post_process_result(cls, result): # override Executor._post_process_result def _strred(srred_trred): srred, trred = srred_trred if srred is not None and trred is not None: return srred * trred elif srred is None: return trred elif trred is None: return srred else: return None result = super(StrredOptFeatureExtractor, cls)._post_process_result(result) srred_scores_key = cls.get_scores_key('srred') trred_scores_key = cls.get_scores_key('trred') strred_scores_key = cls.get_scores_key('strred') strred_all_same_scores_key = cls.get_scores_key('strred_all_same') srred_scores = result.result_dict[srred_scores_key] trred_scores = result.result_dict[trred_scores_key] assert len(srred_scores) == len(trred_scores) # === Way One: consistent with VMAF framework, which is to multiply S and T scores per frame, then average strred_scores = list(map(_strred, zip(srred_scores, trred_scores))) # === Way Two: authentic way of calculating STRRED score: average first, then multiply === strred_all_same_scores = ListStats.nonemean( srred_scores) * ListStats.nonemean(trred_scores) * np.ones( len(srred_scores)) result.result_dict[strred_all_same_scores_key] = strred_all_same_scores result.result_dict[strred_scores_key] = strred_scores # validate for feature in cls.DERIVED_ATOM_FEATURES: assert cls.get_scores_key(feature) in result.result_dict return result
def test_run_testing_proccesses2_without_parallelize(self): exe = VmafConfig.root_path('python', 'vmaf', 'script', 'run_testing.py') cmd = "{exe} PSNR {dataset} --suppress-plot --processes 2".format( exe=exe, dataset=self.dataset_filename) with self.assertRaises(AssertionError): run_process(cmd, shell=True)