From 4671455b567c438522704d9f09ae74213dd73789 Mon Sep 17 00:00:00 2001 From: BlankCheng <913501223@qq.com> Date: Mon, 18 Mar 2024 22:16:04 +0800 Subject: [PATCH] Fix eval func --- desktop_env/evaluators/metrics/gimp.py | 16 ++++++++++++---- .../d16c99dc-2a1e-46f2-b350-d97c86c85c15.json | 16 ++++++++-------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/desktop_env/evaluators/metrics/gimp.py b/desktop_env/evaluators/metrics/gimp.py index e46f5d5..c1208af 100644 --- a/desktop_env/evaluators/metrics/gimp.py +++ b/desktop_env/evaluators/metrics/gimp.py @@ -199,7 +199,7 @@ def structure_check_by_mse(img1, img2, threshold=0.03): def structure_check_by_ssim(img1, img2, threshold=0.9): """Check if two images are approximately the same by SSIM""" - similarity = ssim(np.array(img1), np.array(img2), multichannel=True) + similarity = ssim(np.array(img1), np.array(img2), multichannel=True, channel_axis=-1) print("SSIM: ", similarity) return similarity >= threshold @@ -430,11 +430,11 @@ def check_image_size(src_path, rule): img = Image.open(src_path) # Check the size - if rule["height"] is not None: + if rule.get("height", None) is not None: height_same = img.size[1] == rule["height"] else: height_same = True - if rule["width"] is not None: + if rule.get("width", None) is not None: width_same = img.size[0] == rule["width"] else: width_same = True @@ -607,4 +607,12 @@ if __name__ == "__main__": rule = { "max_size": 500000 } - print(check_image_file_size(src_path, rule)) \ No newline at end of file + print(check_image_file_size(src_path, rule)) + + src_path = "../../../cache/d16c99dc-2a1e-46f2-b350-d97c86c85c15/resized.png" + tgt_path = "../../../cache/d16c99dc-2a1e-46f2-b350-d97c86c85c15/dog_with_background.png" + rule = { + "height": 512 + } + print(check_image_size(src_path, rule)) + print(check_structure_sim_resized(src_path, tgt_path)) \ No newline at end of file diff --git a/evaluation_examples/examples/gimp/d16c99dc-2a1e-46f2-b350-d97c86c85c15.json b/evaluation_examples/examples/gimp/d16c99dc-2a1e-46f2-b350-d97c86c85c15.json index 3029c0c..ca22630 100644 --- a/evaluation_examples/examples/gimp/d16c99dc-2a1e-46f2-b350-d97c86c85c15.json +++ b/evaluation_examples/examples/gimp/d16c99dc-2a1e-46f2-b350-d97c86c85c15.json @@ -86,13 +86,14 @@ ], "func": [ "check_image_size", - "check_structure_sim" + "check_structure_sim_resized" ], "expected": [ { - "type": "vm_file", - "path": "/home/user/Desktop/dog_with_background.png", - "dest": "dog_with_background.png" + "type": "rule", + "rules": { + "height": 512 + } }, { "type": "vm_file", @@ -102,10 +103,9 @@ ], "result": [ { - "type": "rule", - "rules": { - "height": 512 - } + "type": "vm_file", + "path": "/home/user/Desktop/dog_with_background.png", + "dest": "dog_with_background.png" }, { "type": "vm_file",