From 44f2cdd0868c4cebb0c83d3974f59eb9f5f029d6 Mon Sep 17 00:00:00 2001 From: Ajayshyam Date: Thu, 16 Jun 2022 16:04:52 +0530 Subject: [PATCH 1/2] Add resizer in funque as configurable parameter --- funque/core/asset.py | 4 +++- funque/core/custom_feature_extractors.py | 5 +++-- run_funque.py | 18 ++++++++++++++++-- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/funque/core/asset.py b/funque/core/asset.py index 5e27751..83706ca 100644 --- a/funque/core/asset.py +++ b/funque/core/asset.py @@ -50,7 +50,8 @@ class Asset(WorkdirEnabled): def __init__(self, dataset, content_id, asset_id, ref_path, dis_path, asset_dict, - workdir_root=FunqueConfig.workdir_path()): + workdir_root=FunqueConfig.workdir_path(), + enable_resizer=True): """ :param dataset :param content_id: ID of content the asset correspond to within dataset @@ -68,6 +69,7 @@ def __init__(self, dataset, content_id, asset_id, self.ref_path = ref_path self.dis_path = dis_path self.asset_dict = asset_dict + self.enable_resizer = enable_resizer self._assert() diff --git a/funque/core/custom_feature_extractors.py b/funque/core/custom_feature_extractors.py index 2a95505..7c946c3 100644 --- a/funque/core/custom_feature_extractors.py +++ b/funque/core/custom_feature_extractors.py @@ -214,8 +214,9 @@ def _generate_result(self, asset): y_dis, _, _ = yuv_dis # Apply SAST. - y_ref = cv2.resize(y_ref, (w//2, h//2), interpolation=cv2.INTER_CUBIC) - y_dis = cv2.resize(y_dis, (w//2, h//2), interpolation=cv2.INTER_CUBIC) + if asset.enable_resizer: + y_ref = cv2.resize(y_ref, (w//2, h//2), interpolation=cv2.INTER_CUBIC) + y_dis = cv2.resize(y_dis, (w//2, h//2), interpolation=cv2.INTER_CUBIC) if ref_yuv_reader._is_8bit(): y_ref = y_ref.astype(np.double) / (2.0**8 - 1.0) diff --git a/run_funque.py b/run_funque.py index 575f4cc..d0c4e7f 100755 --- a/run_funque.py +++ b/run_funque.py @@ -26,11 +26,20 @@ OUT_FMTS = ['text (default)', 'xml', 'json'] POOL_METHODS = ['mean', 'harmonic_mean', 'min', 'median', 'perc5', 'perc10', 'perc20'] +def str2bool(v): + if isinstance(v, bool): + return v + if v.lower() in ('yes', 'y', 'true', 't', '1'): + return True + elif v.lower() in ('no', 'n', 'false', 'f', '0'): + return False + else: + raise Exception("The string is invalid") def print_usage(): print("usage: " + os.path.basename(sys.argv[0]) \ + " fmt width height ref_path dis_path [--model model_path] [--out-fmt out_fmt] " \ - "[--phone-model] [--ci] [--save-plot plot_dir]\n") + "[--phone-model] [--ci] [--save-plot plot_dir] [--enable_resizer true/false]\n") print("fmt:\n\t" + "\n\t".join(FMTS) + "\n") print("out_fmt:\n\t" + "\n\t".join(OUT_FMTS) + "\n") @@ -46,6 +55,10 @@ def main(): height = int(sys.argv[3]) ref_file = sys.argv[4] dis_file = sys.argv[5] + + enable_resizer_str = get_cmd_option(sys.argv, 6, len(sys.argv), '--enable_resizer') + enable_resizer = str2bool(enable_resizer_str) if enable_resizer_str else True + except ValueError: print_usage() return 2 @@ -93,7 +106,8 @@ def main(): workdir_root=FunqueConfig.workdir_path(), ref_path=ref_file, dis_path=dis_file, - asset_dict={'width':width, 'height':height, 'yuv_type':fmt} + asset_dict={'width':width, 'height':height, 'yuv_type':fmt}, + enable_resizer=enable_resizer ) assets = [asset] From cbd38216c58bc3c3df1fbae92468fe4428376f6f Mon Sep 17 00:00:00 2001 From: Ajayshyam Date: Thu, 16 Jun 2022 16:16:35 +0530 Subject: [PATCH 2/2] Remove double to float conversion in funque vif --- funque/third_party/funque_atoms/vif_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/funque/third_party/funque_atoms/vif_utils.py b/funque/third_party/funque_atoms/vif_utils.py index f593641..a5ca583 100644 --- a/funque/third_party/funque_atoms/vif_utils.py +++ b/funque/third_party/funque_atoms/vif_utils.py @@ -124,8 +124,8 @@ def vif_channel_est(pyr_ref, pyr_dist, subband_keys, M): def vif_spatial(img_ref, img_dist, k=11, sigma_nsq=0.1, stride=1, full=False): - x = img_ref.astype('float32') - y = img_dist.astype('float32') + x = img_ref + y = img_dist _, _, var_x, var_y, cov_xy = moments(x, y, k, stride)