Skip to content

Commit

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

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 Down Expand Up @@ -429,6 +430,7 @@ def _preprocess_segmentation_map(
return segmentation_map

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
4 changes: 4 additions & 0 deletions tests/models/dpt/test_image_processing_dpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def prepare_image_inputs(self, equal_resolution=False, numpify=False, torchify=F


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,6 +101,7 @@ def prepare_semantic_single_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 @@ -170,6 +172,7 @@ def test_keep_aspect_ratio(self):
self.assertEqual(list(pixel_values.shape), [1, 3, 512, 672])

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 @@ -276,6 +279,7 @@ def test_call_segmentation_maps(self):
self.assertTrue(encoding["labels"].max().item() <= 255)

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 2a134f6

Please sign in to comment.