Spaces:
Configuration error
Configuration error
File size: 1,253 Bytes
9bd7d18 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
from PIL import Image
from tensorflow import keras
import sys
import io
sys.path.append("./../app")
import model
model_instance: keras.Model = model.create_model()
def template(filename: str) -> (int, int, Image.Image):
image: Image.Image = Image.open(filename)
width: int
height: int
width, height = image.size
image_bytes: io.BytesIO = io.BytesIO()
image.save(image_bytes, format=image.format)
output_image: Image.Image = model.run_model(image_bytes, model_instance)
return width, height, output_image
def test_image_jpg():
width: int
height: int
output_image: Image.Image
width, height, output_image = template("test_images/test1.jpg")
assert width == output_image.size[0]
assert height == output_image.size[1]
def test_image_png():
width: int
height: int
output_image: Image.Image
width, height, output_image = template("test_images/test2.png")
assert width == output_image.size[0]
assert height == output_image.size[1]
def test_image_jpeg():
width: int
height: int
output_image: Image.Image
width, height, output_image = template("test_images/test3.jpeg")
assert width == output_image.size[0]
assert height == output_image.size[1]
|