diff --git a/src/transformers/models/dpt/image_processing_dpt.py b/src/transformers/models/dpt/image_processing_dpt.py index 2209def01e9c26..e1fd62f32d66e1 100644 --- a/src/transformers/models/dpt/image_processing_dpt.py +++ b/src/transformers/models/dpt/image_processing_dpt.py @@ -282,8 +282,8 @@ def _get_pad(size, size_divisor): return pad(image, ((pad_size_left, pad_size_right), (pad_size_top, pad_size_bottom)), data_format=data_format) + # Copied from transformers.models.beit.image_processing_beit.BeitImageProcessor.reduce_label def reduce_label(self, label: ImageInput) -> np.ndarray: - # Copied from transformers.models.beit.image_processing_beit label = to_numpy_array(label) # Avoid using underflow conversion label[label == 0] = 255 @@ -309,8 +309,6 @@ def _preprocess( size_divisor: int = None, input_data_format: Optional[Union[str, ChannelDimension]] = None, ): - # Adapted from transformers.models.beit.image_processing_beit - if do_reduce_labels: image = self.reduce_label(image) @@ -354,7 +352,6 @@ def _preprocess_image( input_data_format: Optional[Union[str, ChannelDimension]] = None, ) -> np.ndarray: """Preprocesses a single image.""" - # Adapted from transformers.models.beit.image_processing_beit # All transformations expect numpy arrays. image = to_numpy_array(image) if is_scaled_image(image) and do_rescale: @@ -399,7 +396,6 @@ def _preprocess_segmentation_map( input_data_format: Optional[Union[str, ChannelDimension]] = None, ): """Preprocesses a single segmentation map.""" - # Adapted from transformers.models.beit.image_processing_beit # All transformations expect numpy arrays. segmentation_map = to_numpy_array(segmentation_map) # Add an axis to the segmentation maps for transformations. @@ -429,8 +425,8 @@ def _preprocess_segmentation_map( segmentation_map = segmentation_map.astype(np.int64) return segmentation_map + # Copied from transformers.models.beit.image_processing_beit.BeitImageProcessor.__call__ def __call__(self, images, segmentation_maps=None, **kwargs): - # Copied from transformers.models.beit.image_processing_beit # Overrides the `__call__` method of the `Preprocessor` class such that the images and segmentation maps can both # be passed in as positional arguments. return super().__call__(images, segmentation_maps=segmentation_maps, **kwargs) diff --git a/tests/models/dpt/test_image_processing_dpt.py b/tests/models/dpt/test_image_processing_dpt.py index 1c88df576cb983..713c722a4c2b5d 100644 --- a/tests/models/dpt/test_image_processing_dpt.py +++ b/tests/models/dpt/test_image_processing_dpt.py @@ -90,8 +90,8 @@ def prepare_image_inputs(self, equal_resolution=False, numpify=False, torchify=F ) +# Copied from transformers.tests.models.beit.test_image_processing_beit.prepare_semantic_single_inputs def prepare_semantic_single_inputs(): - # Copied from transformers.tests.models.beit.test_image_processing_beit dataset = load_dataset("hf-internal-testing/fixtures_ade20k", split="test", trust_remote_code=True) image = Image.open(dataset[0]["file"]) @@ -100,8 +100,8 @@ def prepare_semantic_single_inputs(): return image, map +# Copied from transformers.tests.models.beit.test_image_processing_beit.prepare_semantic_batch_inputs def prepare_semantic_batch_inputs(): - # Copied from transformers.tests.models.beit.test_image_processing_beit ds = load_dataset("hf-internal-testing/fixtures_ade20k", split="test", trust_remote_code=True) image1 = Image.open(ds[0]["file"]) @@ -171,8 +171,8 @@ def test_keep_aspect_ratio(self): self.assertEqual(list(pixel_values.shape), [1, 3, 512, 672]) + # Copied from transformers.tests.models.beit.test_image_processing_beit.BeitImageProcessingTest.test_call_segmentation_maps def test_call_segmentation_maps(self): - # Copied from transformers.tests.models.beit.test_image_processing_beit # Initialize image_processor image_processor = self.image_processing_class(**self.image_processor_dict) # create random PyTorch tensors @@ -278,8 +278,8 @@ def test_call_segmentation_maps(self): self.assertTrue(encoding["labels"].min().item() >= 0) self.assertTrue(encoding["labels"].max().item() <= 255) + # Copied from transformers.tests.models.beit.test_image_processing_beit.BeitImageProcessingTest.test_reduce_labels def test_reduce_labels(self): - # Copied from transformers.tests.models.beit.test_image_processing_beit # Initialize image_processor image_processor = self.image_processing_class(**self.image_processor_dict)