Skip to content

Commit

Permalink
fix some issues detected by pycharm linter
Browse files Browse the repository at this point in the history
  • Loading branch information
nilfm99 committed Mar 19, 2024
1 parent 71f0f8d commit 5bcde81
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 43 deletions.
8 changes: 4 additions & 4 deletions python/test/cross_validation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions python/vmaf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions python/vmaf/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
6 changes: 3 additions & 3 deletions python/vmaf/core/nn_train_test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions python/vmaf/core/quality_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
16 changes: 8 additions & 8 deletions python/vmaf/routine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion python/vmaf/tools/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions python/vmaf/tools/interpolation_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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])
Expand Down
35 changes: 17 additions & 18 deletions python/vmaf/tools/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -93,7 +93,7 @@ def get_file_name_extension(path):
''
>>> get_file_name_extension("test.265")
'265'
'''
"""
return Path(path).suffix[1:]


Expand All @@ -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):
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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'
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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])


Expand Down Expand Up @@ -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()
Expand All @@ -367,7 +367,7 @@ def func_wrapper(idx_args):


def check_program_exist(program):
'''
"""
>>> check_program_exist("xxxafasd34df")
False
Expand All @@ -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)
Expand All @@ -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')
Expand All @@ -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
Expand Down

0 comments on commit 5bcde81

Please sign in to comment.