2022-03-26 19:38:34 +01:00

27 lines
800 B
Python

import numpy as np
from PIL import Image
from image_prediction.estimator.preprocessor.preprocessors.tensor_conversion import BasicPreprocessor
from image_prediction.estimator.preprocessor.utils import image_to_normalized_tensor, images_to_batch_tensor
def test_image_to_tensor(images):
def inner(image):
tensor = image_to_normalized_tensor(image)
image_re = Image.fromarray(np.uint8(tensor * 255), mode="RGB")
return image == image_re and tensor.ndim == 3
assert all(map(inner, images))
def test_images_to_batch_tensor(images):
tensor = images_to_batch_tensor(images)
assert isinstance(tensor, np.ndarray)
assert tensor.ndim == 4
def test_basic_preprocessor(images):
tensor = BasicPreprocessor().preprocess(images)
assert tensor.ndim == 4