30 lines
982 B
Python
30 lines
982 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 image_conversion_is_correct(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
|
|
|
|
|
|
def images_conversion_is_correct(images, tensor):
|
|
return all([isinstance(tensor, np.ndarray), tensor.ndim == 4, tensor.shape[0] == len(images)])
|
|
|
|
|
|
def test_image_to_tensor(images):
|
|
assert all(map(image_conversion_is_correct, images))
|
|
|
|
|
|
def test_images_to_batch_tensor(images):
|
|
tensor = images_to_batch_tensor(images)
|
|
assert images_conversion_is_correct(images, tensor)
|
|
|
|
|
|
def test_basic_preprocessor(images):
|
|
tensor = BasicPreprocessor()(images)
|
|
assert images_conversion_is_correct(images, tensor)
|