Fix eval func

This commit is contained in:
BlankCheng
2024-03-18 22:16:04 +08:00
parent 3971763c96
commit 4671455b56
2 changed files with 20 additions and 12 deletions

View File

@@ -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))
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))

View File

@@ -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",