🚨🚨🚨 Fix rescale ViVit Efficientnet (#25174)
* Fix rescaling bug * Add tests * Update integration tests * Fix up * Update src/transformers/image_transforms.py * Update test - new possible order in list
This commit is contained in:
@@ -193,3 +193,17 @@ class EfficientNetImageProcessorTest(ImageProcessingSavingTestMixin, unittest.Te
|
||||
self.image_processor_tester.size["width"],
|
||||
),
|
||||
)
|
||||
|
||||
def test_rescale(self):
|
||||
# EfficientNet optionally rescales between -1 and 1 instead of the usual 0 and 1
|
||||
image = np.arange(0, 256, 1, dtype=np.uint8).reshape(1, 8, 32)
|
||||
|
||||
image_processor = self.image_processing_class(**self.image_processor_dict)
|
||||
|
||||
rescaled_image = image_processor.rescale(image, scale=1 / 255)
|
||||
expected_image = image.astype(np.float32) * (2 / 255.0) - 1
|
||||
self.assertTrue(np.allclose(rescaled_image, expected_image))
|
||||
|
||||
rescaled_image = image_processor.rescale(image, scale=1 / 255, offset=False)
|
||||
expected_image = image.astype(np.float32) / 255.0
|
||||
self.assertTrue(np.allclose(rescaled_image, expected_image))
|
||||
|
||||
Reference in New Issue
Block a user