uniformize kwargs for SAM (#34578)

* Make kwargs uniform for SAM

* Remove unused attribute

* Make point_pad_value part of image_kwargs

* Update annotations

* Code review - use existing methods

* Use ProcessorTesterMixin

* Do not add ProcessorTesterMixin everywhere
This commit is contained in:
Tibor Reiss
2024-12-23 13:54:57 +01:00
committed by GitHub
parent 2bb60982ac
commit e10be82b71
2 changed files with 81 additions and 29 deletions

View File

@@ -26,7 +26,7 @@ from transformers.testing_utils import (
)
from transformers.utils import is_tf_available, is_torch_available, is_vision_available
from ...test_processing_common import prepare_image_inputs
from ...test_processing_common import ProcessorTesterMixin, prepare_image_inputs
if is_vision_available():
@@ -43,7 +43,9 @@ if is_tf_available():
@require_vision
@require_torchvision
class SamProcessorTest(unittest.TestCase):
class SamProcessorTest(ProcessorTesterMixin, unittest.TestCase):
processor_class = SamProcessor
def setUp(self):
self.tmpdirname = tempfile.mkdtemp()
image_processor = SamImageProcessor()
@@ -56,11 +58,6 @@ class SamProcessorTest(unittest.TestCase):
def tearDown(self):
shutil.rmtree(self.tmpdirname)
# Processor tester class can't use ProcessorTesterMixin atm because the processor is atypical e.g. only contains an image processor
def prepare_image_inputs(self):
"""This function prepares a list of PIL images."""
return prepare_image_inputs()
def prepare_mask_inputs(self):
"""This function prepares a list of PIL images, or a list of numpy arrays if one specifies numpify=True,
or a list of PyTorch tensors if one specifies torchify=True.
@@ -69,6 +66,21 @@ class SamProcessorTest(unittest.TestCase):
mask_inputs = [Image.fromarray(x) for x in mask_inputs]
return mask_inputs
def test_chat_template_save_loading(self):
self.skipTest("SamProcessor does not have a tokenizer")
def test_image_processor_defaults_preserved_by_image_kwargs(self):
self.skipTest("SamProcessor does not have a tokenizer")
def test_kwargs_overrides_default_image_processor_kwargs(self):
self.skipTest("SamProcessor does not have a tokenizer")
def test_kwargs_overrides_default_tokenizer_kwargs(self):
self.skipTest("SamProcessor does not have a tokenizer")
def test_tokenizer_defaults_preserved_by_kwargs(self):
self.skipTest("SamProcessor does not have a tokenizer")
def test_save_load_pretrained_additional_features(self):
processor = SamProcessor(image_processor=self.get_image_processor())
processor.save_pretrained(self.tmpdirname)
@@ -165,7 +177,7 @@ class TFSamProcessorTest(unittest.TestCase):
def tearDown(self):
shutil.rmtree(self.tmpdirname)
# Processor tester class can't use ProcessorTesterMixin as processor is atypical e.g. only contains an image processor and it assumes torch
# This is to avoid repeating the skipping of the common tests
def prepare_image_inputs(self):
"""This function prepares a list of PIL images."""
return prepare_image_inputs()
@@ -248,7 +260,7 @@ class SamProcessorEquivalenceTest(unittest.TestCase):
def tearDown(self):
shutil.rmtree(self.tmpdirname)
# Processor tester class can't use ProcessorTesterMixin atm because the processor is atypical e.g. only contains an image processor
# This is to avoid repeating the skipping of the common tests
def prepare_image_inputs(self):
"""This function prepares a list of PIL images."""
return prepare_image_inputs()