Skip to content

Commit

Permalink
Fixed # Copied from statements
Browse files Browse the repository at this point in the history
  • Loading branch information
simonreise committed Dec 20, 2024
1 parent 2a134f6 commit d94832b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
8 changes: 2 additions & 6 deletions src/transformers/models/dpt/image_processing_dpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions tests/models/dpt/test_image_processing_dpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand All @@ -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"])
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit d94832b

Please sign in to comment.