Skip to content

Commit

Permalink
Update test script
Browse files Browse the repository at this point in the history
Signed-off-by: ArchieMeng <[email protected]>
  • Loading branch information
ArchieMeng committed Mar 9, 2022
1 parent 8bd67e5 commit 167fee3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
Binary file added tests/0_default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 41 additions & 10 deletions tests/test_upscale.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,43 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from PIL import Image
from srmd_ncnn_vulkan_python import Srmd
import time

start_time = time.time()
input_image = Image.open("input.png")
upscaler = Srmd(0)
output_image = upscaler.process(input_image)
output_image.save("output.png")
print(f"Elapsed time: {time.time() - start_time} secs")
import logging
from pathlib import Path

from PIL import Image, ImageChops, ImageStat
from srmd_ncnn_vulkan_python import SRMD

tests_path = Path(__file__).parent
images_path = (
tests_path.parent / "srmd_ncnn_vulkan_python" / "srmd-ncnn-vulkan" / "images"
)
gpu_id = 0


def _calc_image_diff(image0: Image.Image, image1: Image.Image) -> float:
"""
calculate the percentage of differences between two images
:param image0 Image.Image: the first frame
:param image1 Image.Image: the second frame
:rtype float: the percent difference between the two images
"""
difference = ImageChops.difference(image0, image1)
difference_stat = ImageStat.Stat(difference)
percent_diff = sum(difference_stat.mean) / (len(difference_stat.mean) * 255) * 100
return percent_diff


def test_default():
input_image = Image.open(images_path / "0.jpg")
upscaler = SRMD(gpu_id)
output_image = upscaler.process(input_image)

test_image = Image.open(tests_path / "0_default.png")
percent_diff = _calc_image_diff(test_image, output_image)
logging.getLogger().info(f"%diff: {percent_diff}")

test_image.close()
output_image.close()
input_image.close()

assert percent_diff < 0.5

0 comments on commit 167fee3

Please sign in to comment.