diff --git a/python/test/cross_validation_test.py b/python/test/cross_validation_test.py index 0be71bd8b..525e6c8e8 100644 --- a/python/test/cross_validation_test.py +++ b/python/test/cross_validation_test.py @@ -138,8 +138,8 @@ def test_sample_model_param_list(self): {'n_estimators': 50, 'norm_type': 'clip_0to1', 'random_state': 0}, {'n_estimators': 10, 'norm_type': 'normalize', 'random_state': 0}, ] - for dict, expected_dict in zip(dicts, expected_dicts): - self.assertDictEqual(dict, expected_dict) + for actual_dict, expected_dict in zip(dicts, expected_dicts): + self.assertDictEqual(actual_dict, expected_dict) model_param_search_range = {'norm_type': ['normalize', 'clip_0to1'], 'n_estimators': {'low': 10, 'high': 50, 'decimal': 0}, @@ -163,11 +163,11 @@ def test_find_most_frequent_dict(self): {'norm_type': 'clip_0to1', 'n_estimators': 50, 'random_state': 0}, ] - dict, count = ModelCrossValidation._find_most_frequent_dict(dicts) + actual_dict, count = ModelCrossValidation._find_most_frequent_dict(dicts) expected_dict = {'norm_type': 'clip_0to1', 'n_estimators': 50, 'random_state': 0} expected_count = 2 - self.assertEqual(dict, expected_dict) + self.assertEqual(actual_dict, expected_dict) self.assertEqual(count, expected_count) def test_run_nested_kfold_cross_validation_randomforest(self): diff --git a/python/vmaf/__init__.py b/python/vmaf/__init__.py index 5057b1447..9158397e2 100644 --- a/python/vmaf/__init__.py +++ b/python/vmaf/__init__.py @@ -56,17 +56,17 @@ def project_path(relative_path): def required(path): if not os.path.exists(path): - raise AssertionError("%s does not exist, did you build?" % (path)) + raise AssertionError(f"{path} does not exist, did you build?") return path def convert_pixel_format_ffmpeg2vmafexec(ffmpeg_pix_fmt): - ''' + """ Convert FFmpeg-style pixel format (pix_fmt) to vmaf style. :param ffmpeg_pix_fmt: FFmpeg-style pixel format, for example: yuv420p, yuv420p10le :return: (pixel_format: str, bitdepth: int), for example: (420, 8), (420, 10) - ''' + """ assert ffmpeg_pix_fmt in ['yuv420p', 'yuv422p', 'yuv444p', 'yuv420p10le', 'yuv422p10le', 'yuv444p10le', 'yuv420p12le', 'yuv422p12le', 'yuv444p12le', diff --git a/python/vmaf/config.py b/python/vmaf/config.py index 6c6ca8b7d..4d3481931 100644 --- a/python/vmaf/config.py +++ b/python/vmaf/config.py @@ -224,11 +224,11 @@ class DisplayConfig(object): def show(**kwargs): from vmaf import plt if 'write_to_dir' in kwargs: - format = kwargs['format'] if 'format' in kwargs else 'png' + fmt = kwargs['format'] if 'format' in kwargs else 'png' filedir = kwargs['write_to_dir'] if kwargs['write_to_dir'] is not None else VmafConfig.workspace_path('output') os.makedirs(filedir, exist_ok=True) for fignum in plt.get_fignums(): fig = plt.figure(fignum) - fig.savefig(os.path.join(filedir, str(fignum) + '.' + format), format=format) + fig.savefig(os.path.join(filedir, str(fignum) + '.' + fmt), format=fmt) else: plt.show() diff --git a/python/vmaf/core/nn_train_test_model.py b/python/vmaf/core/nn_train_test_model.py index dc65b65dd..d43e1fd70 100644 --- a/python/vmaf/core/nn_train_test_model.py +++ b/python/vmaf/core/nn_train_test_model.py @@ -240,9 +240,9 @@ def _populate_patches_and_labels(self, xkeys, xys, mode='train'): jv = jv[idx] patches_found = 0 - for (y, x) in zip(iv, jv): - patches_cache[patch_idx] = img[y: y + self.patch_height, - x: x + self.patch_width] + for (yy, xx) in zip(iv, jv): + patches_cache[patch_idx] = img[yy: yy + self.patch_height, + xx: xx + self.patch_width] if mode == 'train': labels_cache[patch_idx] = label diff --git a/python/vmaf/core/quality_runner.py b/python/vmaf/core/quality_runner.py index 456f77d5b..c2a3bd348 100644 --- a/python/vmaf/core/quality_runner.py +++ b/python/vmaf/core/quality_runner.py @@ -1219,8 +1219,7 @@ def _generate_result(self, asset): if use_default_built_in_model: models = [] else: - model0 = [] - model0.append(f'name=vmaf') + model0 = ['name=vmaf'] if self.optional_dict is not None and 'model_filepath' in self.optional_dict: model_filepath = self.optional_dict['model_filepath'] diff --git a/python/vmaf/routine.py b/python/vmaf/routine.py index 92f99cbd7..f283c17bd 100644 --- a/python/vmaf/routine.py +++ b/python/vmaf/routine.py @@ -391,7 +391,7 @@ def run_test_on_dataset(test_dataset, runner_class, ax, for test_asset in test_assets: assert test_asset.groundtruth is not None except AssertionError: - # no groundtruth, try do subjective modeling + # no groundtruth, try to do subjective modeling from sureal.dataset_reader import RawDatasetReader from sureal.subjective_model import DmosModel subj_model_class = kwargs['subj_model_class'] if 'subj_model_class' in kwargs and kwargs['subj_model_class'] is not None else DmosModel @@ -548,11 +548,11 @@ def run_test_on_dataset(test_dataset, runner_class, ax, def print_matplotlib_warning(): - print("Warning: cannot import matplotlib, no picture displayed. " \ - "If you are on Mac OS and have installed matplotlib, you " \ - "possibly need to run: \nsudo pip uninstall python-dateutil \n" \ - "sudo pip install python-dateutil==2.2 \n" \ - "Refer to: http://stackoverflow.com/questions/27630114/matplotlib-issue-on-os-x-importerror-cannot-import-name-thread") + print("Warning: cannot import matplotlib, no picture displayed. " + "If you are on Mac OS and have installed matplotlib, you " + "possibly need to run: \nsudo pip uninstall python-dateutil \n" + "sudo pip install python-dateutil==2.2 \n" + "Refer to: https://stackoverflow.com/questions/27630114/matplotlib-issue-on-os-x-importerror-cannot-import-name-thread") def train_test_vmaf_on_dataset(train_dataset, test_dataset, @@ -569,7 +569,7 @@ def train_test_vmaf_on_dataset(train_dataset, test_dataset, for train_asset in train_assets: assert train_asset.groundtruth is not None except AssertionError: - # no groundtruth, try do subjective modeling + # no groundtruth, try to do subjective modeling from sureal.dataset_reader import RawDatasetReader from sureal.subjective_model import DmosModel subj_model_class = kwargs['subj_model_class'] if 'subj_model_class' in kwargs and kwargs['subj_model_class'] is not None else DmosModel @@ -684,7 +684,7 @@ def train_test_vmaf_on_dataset(train_dataset, test_dataset, for test_asset in test_assets: assert test_asset.groundtruth is not None except AssertionError: - # no groundtruth, try do subjective modeling + # no groundtruth, try to do subjective modeling from sureal.dataset_reader import RawDatasetReader from sureal.subjective_model import DmosModel subj_model_class = kwargs['subj_model_class'] if 'subj_model_class' in kwargs and kwargs['subj_model_class'] is not None else DmosModel diff --git a/python/vmaf/tools/decorator.py b/python/vmaf/tools/decorator.py index 0f59e06ec..83cfa2583 100644 --- a/python/vmaf/tools/decorator.py +++ b/python/vmaf/tools/decorator.py @@ -14,7 +14,7 @@ def deprecated(func): """ Mark a function as deprecated. - It will result in a warning being emmitted when the function is used. + It will result in a warning being emitted when the function is used. """ def new_func(*args, **kwargs): diff --git a/python/vmaf/tools/interpolation_utils.py b/python/vmaf/tools/interpolation_utils.py index 66b665ed8..ba7d1381c 100644 --- a/python/vmaf/tools/interpolation_utils.py +++ b/python/vmaf/tools/interpolation_utils.py @@ -35,7 +35,7 @@ def interpolateRateFromMetric(cls, rdPointsList, arrayDistInLogScale): yk = log_rate[0] segmentOfInterest = 0 for i in range(N-1): - if log_dist[i] <= distInLogScale and log_dist[i+1] >= distInLogScale: + if log_dist[i] <= distInLogScale <= log_dist[i + 1]: distBegin = log_dist[i] yk = log_rate[i] segmentOfInterest = i @@ -72,7 +72,7 @@ def computeParamsForSegments(cls, rdPointsList, log_rate, log_dist, H, delta, d, N = len(rdPointsList) for i in range(N): - if (convertRateUsingLogarithm): + if convertRateUsingLogarithm: log_rate.append(np.log10(rdPointsList[i][0])) else: log_rate.append(rdPointsList[i][0]) diff --git a/python/vmaf/tools/misc.py b/python/vmaf/tools/misc.py index 41bb2e850..dc82f07d5 100644 --- a/python/vmaf/tools/misc.py +++ b/python/vmaf/tools/misc.py @@ -84,7 +84,7 @@ def get_file_name_with_extension(path): def get_file_name_extension(path): - ''' + """ >>> get_file_name_extension("file:///mnt/zli/test.txt") 'txt' >>> get_file_name_extension("test.txt") @@ -93,7 +93,7 @@ def get_file_name_extension(path): '' >>> get_file_name_extension("test.265") '265' - ''' + """ return Path(path).suffix[1:] @@ -118,9 +118,9 @@ def make_parent_dirs_if_nonexist(path): os.makedirs(dst_dir, exist_ok=True) -def delete_dir_if_exists(dir): - if os.path.isdir(dir): - os.rmdir(dir) +def delete_dir_if_exists(dir_to_delete): + if os.path.isdir(dir_to_delete): + os.rmdir(dir_to_delete) def get_normalized_string_from_dict(d): @@ -174,7 +174,7 @@ def indices(a, func): [2, 3] >>> indices([1, 2, 3, 4], lambda x: x==2.5) [] - >>> indices([1, 2, 3, 4], lambda x: x>1 and x<=3) + >>> indices([1, 2, 3, 4], lambda x: 1 < x <= 3) [1, 2] >>> indices([1, 2, 3, 4], lambda x: x in [2, 4]) [1, 3] @@ -250,7 +250,7 @@ def empty_object(): def get_cmd_option(argv, begin, end, option): - ''' + """ >>> get_cmd_option(['a', 'b', 'c', '--xyz', '123'], 3, 5, '--xyz') '123' @@ -264,7 +264,7 @@ def get_cmd_option(argv, begin, end, option): >>> get_cmd_option(['a', 'b', 'c', '--xyz', '123'], 0, 5, 'b') 'c' - ''' + """ itr = None for itr in range(begin, end): if argv[itr] == option: @@ -275,7 +275,7 @@ def get_cmd_option(argv, begin, end, option): def cmd_option_exists(argv, begin, end, option): - ''' + """ >>> cmd_option_exists(['a', 'b', 'c', 'd'], 2, 4, 'c') True @@ -288,7 +288,7 @@ def cmd_option_exists(argv, begin, end, option): >>> cmd_option_exists(['a', 'b', 'c', 'd'], 2, 4, 'b') False - ''' + """ found = False for itr in range(begin, end): if argv[itr] == option: @@ -298,12 +298,12 @@ def cmd_option_exists(argv, begin, end, option): def index_and_value_of_min(l): - ''' + """ >>> index_and_value_of_min([2, 0, 3]) (1, 0) - ''' + """ return min(enumerate(l), key=lambda x: x[1]) @@ -348,7 +348,7 @@ def func_wrapper(idx_args): if not p.is_alive(): active_procs.remove(p) - # check if can add a proc to active_procs (add gradually one per loop) + # check if we can add a proc to active_procs (add gradually one per loop) if len(active_procs) < max_active_procs and len(waiting_procs) > 0: # move one proc from waiting_procs to active_procs p = waiting_procs.pop() @@ -367,7 +367,7 @@ def func_wrapper(idx_args): def check_program_exist(program): - ''' + """ >>> check_program_exist("xxxafasd34df") False @@ -380,7 +380,7 @@ def check_program_exist(program): >>> check_program_exist("pwd") True - ''' + """ try: with open(os.devnull, "wb") as devnull_fd: subprocess.call(program.split(), stdout=devnull_fd) @@ -394,7 +394,7 @@ def check_program_exist(program): def check_scanf_match(string, template): - ''' + """ >>> check_scanf_match('frame00000000.icpf', 'frame%08d.icpf') True >>> check_scanf_match('frame00000003.icpf', 'frame%08d.icpf') @@ -419,8 +419,7 @@ def check_scanf_match(string, template): True >>> check_scanf_match('/mnt/hgfs/ZLI-NFLX-10/USCJND/ref/1920x1080/videoSRC001_1920x1080_30.yuv.avi', '/mnt/hgfs/ZLI-NFLX-10/USCJND/ref/1920x1080/videoSRC001_1920x1080_*.yuv.avi') True - ''' - ret = False + """ try: sscanf(string, template) return True