Unverified Commit b324557a authored by amyeroberts's avatar amyeroberts Committed by GitHub
Browse files

Removal of deprecated vision methods and specify deprecation versions (#24570)

* Removal of deprecated methods and specify versions

* Fix tests
parent 77db28dc
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
# limitations under the License. # limitations under the License.
"""Image processor class for Vilt.""" """Image processor class for Vilt."""
import warnings
from typing import Any, Dict, Iterable, List, Optional, Tuple, Union from typing import Any, Dict, Iterable, List, Optional, Tuple, Union
import numpy as np import numpy as np
...@@ -331,41 +330,6 @@ class ViltImageProcessor(BaseImageProcessor): ...@@ -331,41 +330,6 @@ class ViltImageProcessor(BaseImageProcessor):
return BatchFeature(data=data, tensor_type=return_tensors) return BatchFeature(data=data, tensor_type=return_tensors)
def pad_and_create_pixel_mask(
self,
pixel_values_list: List[ImageInput],
return_tensors: Optional[Union[str, TensorType]] = None,
data_format: Optional[ChannelDimension] = None,
) -> BatchFeature:
"""
Pads a batch of images with zeros to the size of largest height and width in the batch and returns their
corresponding pixel mask.
Args:
images (`List[np.ndarray]`):
Batch of images to pad.
return_tensors (`str` or `TensorType`, *optional*):
The type of tensors to return. Can be one of:
- Unset: Return a list of `np.ndarray`.
- `TensorType.TENSORFLOW` or `'tf'`: Return a batch of type `tf.Tensor`.
- `TensorType.PYTORCH` or `'pt'`: Return a batch of type `torch.Tensor`.
- `TensorType.NUMPY` or `'np'`: Return a batch of type `np.ndarray`.
- `TensorType.JAX` or `'jax'`: Return a batch of type `jax.numpy.ndarray`.
data_format (`str` or `ChannelDimension`, *optional*):
The channel dimension format of the image. If not provided, it will be the same as the input image.
"""
warnings.warn(
"This method is deprecated and will be removed in v4.26.0. Please use pad instead.", FutureWarning
)
# pad expects a list of np.ndarray, but the previous feature extractors expected torch tensors
images = [to_numpy_array(image) for image in pixel_values_list]
return self.pad(
images=images,
return_pixel_mask=True,
return_tensors=return_tensors,
data_format=data_format,
)
def preprocess( def preprocess(
self, self,
images: ImageInput, images: ImageInput,
......
...@@ -729,15 +729,6 @@ class YolosImageProcessor(BaseImageProcessor): ...@@ -729,15 +729,6 @@ class YolosImageProcessor(BaseImageProcessor):
self.image_std = image_std if image_std is not None else IMAGENET_DEFAULT_STD self.image_std = image_std if image_std is not None else IMAGENET_DEFAULT_STD
self.do_pad = do_pad self.do_pad = do_pad
@property
# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.max_size
def max_size(self):
logger.warning(
"The `max_size` parameter is deprecated and will be removed in v4.27. "
"Please specify in `size['longest_edge'] instead`.",
)
return self.size["longest_edge"]
@classmethod @classmethod
# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.from_dict with Detr->Yolos # Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.from_dict with Detr->Yolos
def from_dict(cls, image_processor_dict: Dict[str, Any], **kwargs): def from_dict(cls, image_processor_dict: Dict[str, Any], **kwargs):
...@@ -782,7 +773,7 @@ class YolosImageProcessor(BaseImageProcessor): ...@@ -782,7 +773,7 @@ class YolosImageProcessor(BaseImageProcessor):
# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.prepare # Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.prepare
def prepare(self, image, target, return_segmentation_masks=False, masks_path=None): def prepare(self, image, target, return_segmentation_masks=False, masks_path=None):
logger.warning_once( logger.warning_once(
"The `prepare` method is deprecated and will be removed in a future version. " "The `prepare` method is deprecated and will be removed in a v4.33. "
"Please use `prepare_annotation` instead. Note: the `prepare_annotation` method " "Please use `prepare_annotation` instead. Note: the `prepare_annotation` method "
"does not return the image anymore.", "does not return the image anymore.",
) )
...@@ -791,23 +782,17 @@ class YolosImageProcessor(BaseImageProcessor): ...@@ -791,23 +782,17 @@ class YolosImageProcessor(BaseImageProcessor):
# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.convert_coco_poly_to_mask # Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.convert_coco_poly_to_mask
def convert_coco_poly_to_mask(self, *args, **kwargs): def convert_coco_poly_to_mask(self, *args, **kwargs):
logger.warning_once( logger.warning_once("The `convert_coco_poly_to_mask` method is deprecated and will be removed in v4.33. ")
"The `convert_coco_poly_to_mask` method is deprecated and will be removed in a future version. "
)
return convert_coco_poly_to_mask(*args, **kwargs) return convert_coco_poly_to_mask(*args, **kwargs)
# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.prepare_coco_detection with DETR->Yolos # Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.prepare_coco_detection with DETR->Yolos
def prepare_coco_detection(self, *args, **kwargs): def prepare_coco_detection(self, *args, **kwargs):
logger.warning_once( logger.warning_once("The `prepare_coco_detection` method is deprecated and will be removed in v4.33. ")
"The `prepare_coco_detection` method is deprecated and will be removed in a future version. "
)
return prepare_coco_detection_annotation(*args, **kwargs) return prepare_coco_detection_annotation(*args, **kwargs)
# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.prepare_coco_panoptic # Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.prepare_coco_panoptic
def prepare_coco_panoptic(self, *args, **kwargs): def prepare_coco_panoptic(self, *args, **kwargs):
logger.warning_once( logger.warning_once("The `prepare_coco_panoptic` method is deprecated and will be removed in v4.33. ")
"The `prepare_coco_panoptic` method is deprecated and will be removed in a future version. "
)
return prepare_coco_panoptic_annotation(*args, **kwargs) return prepare_coco_panoptic_annotation(*args, **kwargs)
# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.resize # Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.resize
...@@ -1010,7 +995,7 @@ class YolosImageProcessor(BaseImageProcessor): ...@@ -1010,7 +995,7 @@ class YolosImageProcessor(BaseImageProcessor):
""" """
if "pad_and_return_pixel_mask" in kwargs: if "pad_and_return_pixel_mask" in kwargs:
logger.warning_once( logger.warning_once(
"The `pad_and_return_pixel_mask` argument is deprecated and will be removed in a future version, " "The `pad_and_return_pixel_mask` argument is deprecated and will be removed in v4.33, "
"use `do_pad` instead.", "use `do_pad` instead.",
) )
do_pad = kwargs.pop("pad_and_return_pixel_mask") do_pad = kwargs.pop("pad_and_return_pixel_mask")
...@@ -1018,7 +1003,7 @@ class YolosImageProcessor(BaseImageProcessor): ...@@ -1018,7 +1003,7 @@ class YolosImageProcessor(BaseImageProcessor):
max_size = None max_size = None
if "max_size" in kwargs: if "max_size" in kwargs:
logger.warning_once( logger.warning_once(
"The `max_size` argument is deprecated and will be removed in a future version, use" "The `max_size` argument is deprecated and will be removed in v4.33, use"
" `size['longest_edge']` instead.", " `size['longest_edge']` instead.",
) )
size = kwargs.pop("max_size") size = kwargs.pop("max_size")
......
...@@ -236,23 +236,3 @@ class BridgeTowerImageProcessingTest(ImageProcessingSavingTestMixin, unittest.Te ...@@ -236,23 +236,3 @@ class BridgeTowerImageProcessingTest(ImageProcessingSavingTestMixin, unittest.Te
expected_width, expected_width,
), ),
) )
def test_equivalence_pad_and_create_pixel_mask(self):
# Initialize image processors
image_processing_1 = self.image_processing_class(**self.image_processor_dict)
image_processing_2 = self.image_processing_class(do_resize=False, do_normalize=False, do_rescale=False)
# create random PyTorch tensors
image_inputs = prepare_image_inputs(self.image_processor_tester, equal_resolution=False, torchify=True)
for image in image_inputs:
self.assertIsInstance(image, torch.Tensor)
# Test whether the method "pad_and_return_pixel_mask" and calling the image processor return the same tensors
encoded_images_with_method = image_processing_1.pad_and_create_pixel_mask(image_inputs, return_tensors="pt")
encoded_images = image_processing_2(image_inputs, return_tensors="pt")
self.assertTrue(
torch.allclose(encoded_images_with_method["pixel_values"], encoded_images["pixel_values"], atol=1e-4)
)
self.assertTrue(
torch.allclose(encoded_images_with_method["pixel_mask"], encoded_images["pixel_mask"], atol=1e-4)
)
...@@ -244,26 +244,6 @@ class ConditionalDetrImageProcessingTest(ImageProcessingSavingTestMixin, unittes ...@@ -244,26 +244,6 @@ class ConditionalDetrImageProcessingTest(ImageProcessingSavingTestMixin, unittes
), ),
) )
def test_equivalence_pad_and_create_pixel_mask(self):
# Initialize image_processings
image_processing_1 = self.image_processing_class(**self.image_processor_dict)
image_processing_2 = self.image_processing_class(do_resize=False, do_normalize=False, do_rescale=False)
# create random PyTorch tensors
image_inputs = prepare_image_inputs(self.image_processor_tester, equal_resolution=False, torchify=True)
for image in image_inputs:
self.assertIsInstance(image, torch.Tensor)
# Test whether the method "pad_and_return_pixel_mask" and calling the image processor return the same tensors
encoded_images_with_method = image_processing_1.pad_and_create_pixel_mask(image_inputs, return_tensors="pt")
encoded_images = image_processing_2(image_inputs, return_tensors="pt")
self.assertTrue(
torch.allclose(encoded_images_with_method["pixel_values"], encoded_images["pixel_values"], atol=1e-4)
)
self.assertTrue(
torch.allclose(encoded_images_with_method["pixel_mask"], encoded_images["pixel_mask"], atol=1e-4)
)
@slow @slow
def test_call_pytorch_with_coco_detection_annotations(self): def test_call_pytorch_with_coco_detection_annotations(self):
# prepare image and target # prepare image and target
......
...@@ -246,27 +246,6 @@ class DeformableDetrImageProcessingTest(ImageProcessingSavingTestMixin, unittest ...@@ -246,27 +246,6 @@ class DeformableDetrImageProcessingTest(ImageProcessingSavingTestMixin, unittest
), ),
) )
def test_equivalence_pad_and_create_pixel_mask(self):
# Initialize image_processings
image_processing_1 = self.image_processing_class(**self.image_processor_dict)
image_processing_2 = self.image_processing_class(do_resize=False, do_normalize=False, do_rescale=False)
# create random PyTorch tensors
image_inputs = prepare_image_inputs(self.image_processor_tester, equal_resolution=False, torchify=True)
for image in image_inputs:
self.assertIsInstance(image, torch.Tensor)
# Test whether the method "pad_and_return_pixel_mask" and calling the image processor return the same tensors
encoded_images_with_method = image_processing_1.pad_and_create_pixel_mask(image_inputs, return_tensors="pt")
encoded_images = image_processing_2(image_inputs, return_tensors="pt")
self.assertTrue(
torch.allclose(encoded_images_with_method["pixel_values"], encoded_images["pixel_values"], atol=1e-4)
)
self.assertTrue(
torch.allclose(encoded_images_with_method["pixel_mask"], encoded_images["pixel_mask"], atol=1e-4)
)
@slow @slow
def test_call_pytorch_with_coco_detection_annotations(self): def test_call_pytorch_with_coco_detection_annotations(self):
# prepare image and target # prepare image and target
......
...@@ -240,27 +240,6 @@ class DetaImageProcessingTest(ImageProcessingSavingTestMixin, unittest.TestCase) ...@@ -240,27 +240,6 @@ class DetaImageProcessingTest(ImageProcessingSavingTestMixin, unittest.TestCase)
), ),
) )
def test_equivalence_pad_and_create_pixel_mask(self):
# Initialize image_processings
image_processing_1 = self.image_processing_class(**self.image_processor_dict)
image_processing_2 = self.image_processing_class(do_resize=False, do_normalize=False, do_rescale=False)
# create random PyTorch tensors
image_inputs = prepare_image_inputs(self.image_processor_tester, equal_resolution=False, torchify=True)
for image in image_inputs:
self.assertIsInstance(image, torch.Tensor)
# Test whether the method "pad_and_return_pixel_mask" and calling the image processor return the same tensors
encoded_images_with_method = image_processing_1.pad_and_create_pixel_mask(image_inputs, return_tensors="pt")
encoded_images = image_processing_2(image_inputs, return_tensors="pt")
self.assertTrue(
torch.allclose(encoded_images_with_method["pixel_values"], encoded_images["pixel_values"], atol=1e-4)
)
self.assertTrue(
torch.allclose(encoded_images_with_method["pixel_mask"], encoded_images["pixel_mask"], atol=1e-4)
)
@slow @slow
def test_call_pytorch_with_coco_detection_annotations(self): def test_call_pytorch_with_coco_detection_annotations(self):
# prepare image and target # prepare image and target
......
...@@ -247,26 +247,6 @@ class DetrImageProcessingTest(ImageProcessingSavingTestMixin, unittest.TestCase) ...@@ -247,26 +247,6 @@ class DetrImageProcessingTest(ImageProcessingSavingTestMixin, unittest.TestCase)
), ),
) )
def test_equivalence_pad_and_create_pixel_mask(self):
# Initialize image_processings
image_processing_1 = self.image_processing_class(**self.image_processor_dict)
image_processing_2 = self.image_processing_class(do_resize=False, do_normalize=False, do_rescale=False)
# create random PyTorch tensors
image_inputs = prepare_image_inputs(self.image_processor_tester, equal_resolution=False, torchify=True)
for image in image_inputs:
self.assertIsInstance(image, torch.Tensor)
# Test whether the method "pad_and_return_pixel_mask" and calling the image processor return the same tensors
encoded_images_with_method = image_processing_1.pad_and_create_pixel_mask(image_inputs, return_tensors="pt")
encoded_images = image_processing_2(image_inputs, return_tensors="pt")
self.assertTrue(
torch.allclose(encoded_images_with_method["pixel_values"], encoded_images["pixel_values"], atol=1e-4)
)
self.assertTrue(
torch.allclose(encoded_images_with_method["pixel_mask"], encoded_images["pixel_mask"], atol=1e-4)
)
@slow @slow
def test_call_pytorch_with_coco_detection_annotations(self): def test_call_pytorch_with_coco_detection_annotations(self):
# prepare image and target # prepare image and target
......
...@@ -147,7 +147,6 @@ class Mask2FormerImageProcessingTest(ImageProcessingSavingTestMixin, unittest.Te ...@@ -147,7 +147,6 @@ class Mask2FormerImageProcessingTest(ImageProcessingSavingTestMixin, unittest.Te
self.assertTrue(hasattr(image_processing, "do_normalize")) self.assertTrue(hasattr(image_processing, "do_normalize"))
self.assertTrue(hasattr(image_processing, "do_resize")) self.assertTrue(hasattr(image_processing, "do_resize"))
self.assertTrue(hasattr(image_processing, "size")) self.assertTrue(hasattr(image_processing, "size"))
self.assertTrue(hasattr(image_processing, "max_size"))
self.assertTrue(hasattr(image_processing, "ignore_index")) self.assertTrue(hasattr(image_processing, "ignore_index"))
self.assertTrue(hasattr(image_processing, "num_labels")) self.assertTrue(hasattr(image_processing, "num_labels"))
...@@ -263,28 +262,6 @@ class Mask2FormerImageProcessingTest(ImageProcessingSavingTestMixin, unittest.Te ...@@ -263,28 +262,6 @@ class Mask2FormerImageProcessingTest(ImageProcessingSavingTestMixin, unittest.Te
), ),
) )
def test_equivalence_pad_and_create_pixel_mask(self):
# Initialize image_processings
image_processing_1 = self.image_processing_class(**self.image_processor_dict)
image_processing_2 = self.image_processing_class(
do_resize=False, do_normalize=False, do_rescale=False, num_labels=self.image_processor_tester.num_classes
)
# create random PyTorch tensors
image_inputs = prepare_image_inputs(self.image_processor_tester, equal_resolution=False, torchify=True)
for image in image_inputs:
self.assertIsInstance(image, torch.Tensor)
# Test whether the method "pad_and_return_pixel_mask" and calling the image processor return the same tensors
encoded_images_with_method = image_processing_1.encode_inputs(image_inputs, return_tensors="pt")
encoded_images = image_processing_2(image_inputs, return_tensors="pt")
self.assertTrue(
torch.allclose(encoded_images_with_method["pixel_values"], encoded_images["pixel_values"], atol=1e-4)
)
self.assertTrue(
torch.allclose(encoded_images_with_method["pixel_mask"], encoded_images["pixel_mask"], atol=1e-4)
)
def comm_get_image_processing_inputs( def comm_get_image_processing_inputs(
self, with_segmentation_maps=False, is_instance_map=False, segmentation_type="np" self, with_segmentation_maps=False, is_instance_map=False, segmentation_type="np"
): ):
......
...@@ -147,7 +147,6 @@ class MaskFormerImageProcessingTest(ImageProcessingSavingTestMixin, unittest.Tes ...@@ -147,7 +147,6 @@ class MaskFormerImageProcessingTest(ImageProcessingSavingTestMixin, unittest.Tes
self.assertTrue(hasattr(image_processing, "do_normalize")) self.assertTrue(hasattr(image_processing, "do_normalize"))
self.assertTrue(hasattr(image_processing, "do_resize")) self.assertTrue(hasattr(image_processing, "do_resize"))
self.assertTrue(hasattr(image_processing, "size")) self.assertTrue(hasattr(image_processing, "size"))
self.assertTrue(hasattr(image_processing, "max_size"))
self.assertTrue(hasattr(image_processing, "ignore_index")) self.assertTrue(hasattr(image_processing, "ignore_index"))
self.assertTrue(hasattr(image_processing, "num_labels")) self.assertTrue(hasattr(image_processing, "num_labels"))
...@@ -263,28 +262,6 @@ class MaskFormerImageProcessingTest(ImageProcessingSavingTestMixin, unittest.Tes ...@@ -263,28 +262,6 @@ class MaskFormerImageProcessingTest(ImageProcessingSavingTestMixin, unittest.Tes
), ),
) )
def test_equivalence_pad_and_create_pixel_mask(self):
# Initialize image_processings
image_processing_1 = self.image_processing_class(**self.image_processor_dict)
image_processing_2 = self.image_processing_class(
do_resize=False, do_normalize=False, do_rescale=False, num_labels=self.image_processor_tester.num_classes
)
# create random PyTorch tensors
image_inputs = prepare_image_inputs(self.image_processor_tester, equal_resolution=False, torchify=True)
for image in image_inputs:
self.assertIsInstance(image, torch.Tensor)
# Test whether the method "pad_and_return_pixel_mask" and calling the image processor return the same tensors
encoded_images_with_method = image_processing_1.encode_inputs(image_inputs, return_tensors="pt")
encoded_images = image_processing_2(image_inputs, return_tensors="pt")
self.assertTrue(
torch.allclose(encoded_images_with_method["pixel_values"], encoded_images["pixel_values"], atol=1e-4)
)
self.assertTrue(
torch.allclose(encoded_images_with_method["pixel_mask"], encoded_images["pixel_mask"], atol=1e-4)
)
def comm_get_image_processing_inputs( def comm_get_image_processing_inputs(
self, with_segmentation_maps=False, is_instance_map=False, segmentation_type="np" self, with_segmentation_maps=False, is_instance_map=False, segmentation_type="np"
): ):
......
...@@ -286,36 +286,6 @@ class OneFormerImageProcessingTest(ImageProcessingSavingTestMixin, unittest.Test ...@@ -286,36 +286,6 @@ class OneFormerImageProcessingTest(ImageProcessingSavingTestMixin, unittest.Test
), ),
) )
def test_equivalence_pad_and_create_pixel_mask(self):
# Initialize image_processors
image_processor_1 = self.image_processing_class(**self.image_processor_dict)
image_processor_2 = self.image_processing_class(
do_resize=False,
do_normalize=False,
do_rescale=False,
num_labels=self.image_processing_tester.num_classes,
class_info_file="ade20k_panoptic.json",
num_text=self.image_processing_tester.num_text,
repo_path="shi-labs/oneformer_demo",
)
# create random PyTorch tensors
image_inputs = prepare_image_inputs(self.image_processing_tester, equal_resolution=False, torchify=True)
for image in image_inputs:
self.assertIsInstance(image, torch.Tensor)
# Test whether the method "pad_and_return_pixel_mask" and calling the image processor return the same tensors
encoded_images_with_method = image_processor_1.encode_inputs(
image_inputs, ["semantic"] * len(image_inputs), return_tensors="pt"
)
encoded_images = image_processor_2(image_inputs, ["semantic"] * len(image_inputs), return_tensors="pt")
self.assertTrue(
torch.allclose(encoded_images_with_method["pixel_values"], encoded_images["pixel_values"], atol=1e-4)
)
self.assertTrue(
torch.allclose(encoded_images_with_method["pixel_mask"], encoded_images["pixel_mask"], atol=1e-4)
)
def comm_get_image_processor_inputs( def comm_get_image_processor_inputs(
self, with_segmentation_maps=False, is_instance_map=False, segmentation_type="np" self, with_segmentation_maps=False, is_instance_map=False, segmentation_type="np"
): ):
......
...@@ -355,41 +355,6 @@ class OneFormerProcessingTest(unittest.TestCase): ...@@ -355,41 +355,6 @@ class OneFormerProcessingTest(unittest.TestCase):
(self.processing_tester.batch_size, expected_sequence_length), (self.processing_tester.batch_size, expected_sequence_length),
) )
def test_equivalence_pad_and_create_pixel_mask(self):
# Initialize processors
processor_1 = self.processing_class(**self.processor_dict)
image_processor = OneFormerImageProcessor(
do_resize=False,
do_normalize=False,
do_rescale=False,
num_labels=self.processing_tester.num_classes,
class_info_file="ade20k_panoptic.json",
num_text=self.processing_tester.num_text,
)
tokenizer = CLIPTokenizer.from_pretrained("shi-labs/oneformer_ade20k_swin_tiny")
processor_2 = self.processing_class(
image_processor=image_processor, tokenizer=tokenizer, max_seq_length=77, task_seq_length=77
)
# create random PyTorch tensors
image_inputs = prepare_image_inputs(self.processing_tester, equal_resolution=False, torchify=True)
for image in image_inputs:
self.assertIsInstance(image, torch.Tensor)
# Test whether the method "pad_and_return_pixel_mask" and calling the image processor return the same tensors
encoded_images_with_method = processor_1.encode_inputs(
image_inputs, ["semantic"] * len(image_inputs), return_tensors="pt"
)
encoded_images = processor_2(image_inputs, ["semantic"] * len(image_inputs), return_tensors="pt")
self.assertTrue(
torch.allclose(encoded_images_with_method["pixel_values"], encoded_images["pixel_values"], atol=1e-4)
)
self.assertTrue(
torch.allclose(encoded_images_with_method["pixel_mask"], encoded_images["pixel_mask"], atol=1e-4)
)
def comm_get_processor_inputs(self, with_segmentation_maps=False, is_instance_map=False, segmentation_type="np"): def comm_get_processor_inputs(self, with_segmentation_maps=False, is_instance_map=False, segmentation_type="np"):
processor = self.processing_class(**self.processor_dict) processor = self.processing_class(**self.processor_dict)
# prepare image and target # prepare image and target
......
...@@ -237,23 +237,3 @@ class ViltImageProcessingTest(ImageProcessingSavingTestMixin, unittest.TestCase) ...@@ -237,23 +237,3 @@ class ViltImageProcessingTest(ImageProcessingSavingTestMixin, unittest.TestCase)
expected_width, expected_width,
), ),
) )
def test_equivalence_pad_and_create_pixel_mask(self):
# Initialize image_processings
image_processing_1 = self.image_processing_class(**self.image_processor_dict)
image_processing_2 = self.image_processing_class(do_resize=False, do_normalize=False, do_rescale=False)
# create random PyTorch tensors
image_inputs = prepare_image_inputs(self.image_processor_tester, equal_resolution=False, torchify=True)
for image in image_inputs:
self.assertIsInstance(image, torch.Tensor)
# Test whether the method "pad_and_return_pixel_mask" and calling the image processor return the same tensors
encoded_images_with_method = image_processing_1.pad_and_create_pixel_mask(image_inputs, return_tensors="pt")
encoded_images = image_processing_2(image_inputs, return_tensors="pt")
self.assertTrue(
torch.allclose(encoded_images_with_method["pixel_values"], encoded_images["pixel_values"], atol=1e-4)
)
self.assertTrue(
torch.allclose(encoded_images_with_method["pixel_mask"], encoded_images["pixel_mask"], atol=1e-4)
)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment