Loading test/preprocess/test_pillow.py +22 −1 Original line number Diff line number Diff line Loading @@ -6,7 +6,7 @@ from PIL import Image from hbutils.testing import tmatrix from imgutils.preprocess.pillow import PillowResize, _get_pillow_resample, PillowCenterCrop, PillowToTensor, \ PillowMaybeToTensor, PillowNormalize PillowMaybeToTensor, PillowNormalize, create_pillow_transforms from imgutils.preprocess.torchvision import _get_interpolation_mode from test.testings import get_testfile Loading Loading @@ -408,6 +408,27 @@ class TestPreprocessPillow: ttotensor = ToTensor() np.testing.assert_array_almost_equal(ptotensor(image), ttotensor(image).numpy()) @skipUnless(_TORCHVISION_AVAILABLE, 'Torchvision required') @pytest.mark.parametrize(*tmatrix({ 'src_image': [ 'png_640.png', 'png_640_m90.png', ], 'mode': [ 'I', 'I;16', 'F', '1', 'L', 'LA', 'P', 'RGB', 'YCbCr', 'RGBA', 'CMYK', ] })) def test_to_tensor(self, src_image, mode): from torchvision.transforms import ToTensor image = Image.open(get_testfile(src_image)) image = image.convert(mode) assert image.mode == mode ptotensor = create_pillow_transforms({'type': 'to_tensor'}) ttotensor = ToTensor() np.testing.assert_array_almost_equal(ptotensor(image), ttotensor(image).numpy()) def test_to_tensor_invalid(self): ptotensor = PillowToTensor() with pytest.raises(TypeError): Loading test/preprocess/test_pillow_compose.py +10 −0 Original line number Diff line number Diff line Loading @@ -215,3 +215,13 @@ PillowCompose( ptrans(image), ttrans(image).numpy(), ) def test_create_transform_invalid(self): with pytest.raises(TypeError): _ = create_pillow_transforms(None) with pytest.raises(TypeError): _ = create_pillow_transforms(1) with pytest.raises(TypeError): _ = create_pillow_transforms('str') test/preprocess/test_torchvision.py +15 −0 Original line number Diff line number Diff line Loading @@ -56,6 +56,7 @@ class TestPreprocessPillow: with pytest.raises(ValueError): _ = _get_interpolation_mode('') @skipUnless(_TORCHVISION_AVAILABLE, 'Torchvision required.') def test_get_interpolation_mode_invalid(self): with pytest.raises(TypeError): _ = _get_interpolation_mode(None) Loading Loading @@ -117,3 +118,17 @@ class TestPreprocessPillow: ttrans = create_torchvision_transforms({'type': 'to_tensor'}) result = ttrans(image) assert tuple(result.shape) == (channels, image.height, image.width) @skipUnless(_TORCHVISION_AVAILABLE, 'Torchvision required.') def test_create_transform_invalid(self): with pytest.raises(TypeError): _ = create_torchvision_transforms(None) with pytest.raises(TypeError): _ = create_torchvision_transforms(1) with pytest.raises(TypeError): _ = create_torchvision_transforms('str') @skipUnless(not _TORCHVISION_AVAILABLE, 'Non-torchvision required.') def test_create_transform_non_torchvision(self): with pytest.raises(EnvironmentError): _ = create_torchvision_transforms([]) Loading
test/preprocess/test_pillow.py +22 −1 Original line number Diff line number Diff line Loading @@ -6,7 +6,7 @@ from PIL import Image from hbutils.testing import tmatrix from imgutils.preprocess.pillow import PillowResize, _get_pillow_resample, PillowCenterCrop, PillowToTensor, \ PillowMaybeToTensor, PillowNormalize PillowMaybeToTensor, PillowNormalize, create_pillow_transforms from imgutils.preprocess.torchvision import _get_interpolation_mode from test.testings import get_testfile Loading Loading @@ -408,6 +408,27 @@ class TestPreprocessPillow: ttotensor = ToTensor() np.testing.assert_array_almost_equal(ptotensor(image), ttotensor(image).numpy()) @skipUnless(_TORCHVISION_AVAILABLE, 'Torchvision required') @pytest.mark.parametrize(*tmatrix({ 'src_image': [ 'png_640.png', 'png_640_m90.png', ], 'mode': [ 'I', 'I;16', 'F', '1', 'L', 'LA', 'P', 'RGB', 'YCbCr', 'RGBA', 'CMYK', ] })) def test_to_tensor(self, src_image, mode): from torchvision.transforms import ToTensor image = Image.open(get_testfile(src_image)) image = image.convert(mode) assert image.mode == mode ptotensor = create_pillow_transforms({'type': 'to_tensor'}) ttotensor = ToTensor() np.testing.assert_array_almost_equal(ptotensor(image), ttotensor(image).numpy()) def test_to_tensor_invalid(self): ptotensor = PillowToTensor() with pytest.raises(TypeError): Loading
test/preprocess/test_pillow_compose.py +10 −0 Original line number Diff line number Diff line Loading @@ -215,3 +215,13 @@ PillowCompose( ptrans(image), ttrans(image).numpy(), ) def test_create_transform_invalid(self): with pytest.raises(TypeError): _ = create_pillow_transforms(None) with pytest.raises(TypeError): _ = create_pillow_transforms(1) with pytest.raises(TypeError): _ = create_pillow_transforms('str')
test/preprocess/test_torchvision.py +15 −0 Original line number Diff line number Diff line Loading @@ -56,6 +56,7 @@ class TestPreprocessPillow: with pytest.raises(ValueError): _ = _get_interpolation_mode('') @skipUnless(_TORCHVISION_AVAILABLE, 'Torchvision required.') def test_get_interpolation_mode_invalid(self): with pytest.raises(TypeError): _ = _get_interpolation_mode(None) Loading Loading @@ -117,3 +118,17 @@ class TestPreprocessPillow: ttrans = create_torchvision_transforms({'type': 'to_tensor'}) result = ttrans(image) assert tuple(result.shape) == (channels, image.height, image.width) @skipUnless(_TORCHVISION_AVAILABLE, 'Torchvision required.') def test_create_transform_invalid(self): with pytest.raises(TypeError): _ = create_torchvision_transforms(None) with pytest.raises(TypeError): _ = create_torchvision_transforms(1) with pytest.raises(TypeError): _ = create_torchvision_transforms('str') @skipUnless(not _TORCHVISION_AVAILABLE, 'Non-torchvision required.') def test_create_transform_non_torchvision(self): with pytest.raises(EnvironmentError): _ = create_torchvision_transforms([])