Add check before int casting for PIL conversion (#21969)

* Add check before int casting for PIL conversion

* Line length

* Tidier logic
This commit is contained in:
amyeroberts
2023-03-07 11:14:09 +00:00
committed by GitHub
parent 5b28b78332
commit 4063fd9cba
2 changed files with 19 additions and 2 deletions

View File

@@ -96,6 +96,11 @@ class ImageTransformsTester(unittest.TestCase):
# make sure image is correctly rescaled
self.assertTrue(np.abs(np.asarray(pil_image)).sum() > 0)
# Make sure that an exception is raised if image is not in [0, 1]
image = np.random.randn(*image_shape).astype(dtype)
with self.assertRaises(ValueError):
to_pil_image(image)
@require_tf
def test_to_pil_image_from_tensorflow(self):
# channels_first