Rescale image back if it was scaled during PIL conversion (#22458)

* Rescale image back if it was scaled during PIL conversion

* do_rescale is defined if PIL image passed in
This commit is contained in:
amyeroberts
2023-03-30 11:29:11 +01:00
committed by GitHub
parent c15f937581
commit 154c6bb7ac
2 changed files with 42 additions and 19 deletions

View File

@@ -249,6 +249,14 @@ class ImageTransformsTester(unittest.TestCase):
# PIL size is in (width, height) order
self.assertEqual(resized_image.size, (40, 30))
# Check an image with float values between 0-1 is returned with values in this range
image = np.random.rand(3, 224, 224)
resized_image = resize(image, (30, 40))
self.assertIsInstance(resized_image, np.ndarray)
self.assertEqual(resized_image.shape, (3, 30, 40))
self.assertTrue(np.all(resized_image >= 0))
self.assertTrue(np.all(resized_image <= 1))
def test_normalize(self):
image = np.random.randint(0, 256, (224, 224, 3)) / 255