Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d92cd4b

Browse files
committedDec 19, 2024·
Use ProcessorTesterMixin
1 parent 96dd98f commit d92cd4b

File tree

1 file changed

+53
-17
lines changed

1 file changed

+53
-17
lines changed
 

‎tests/models/sam/test_processor_sam.py

+53-17
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
)
2727
from transformers.utils import is_tf_available, is_torch_available, is_vision_available
2828

29-
from ...test_processing_common import prepare_image_inputs
29+
from ...test_processing_common import ProcessorTesterMixin
3030

3131

3232
if is_vision_available():
@@ -43,7 +43,9 @@
4343

4444
@require_vision
4545
@require_torchvision
46-
class SamProcessorTest(unittest.TestCase):
46+
class SamProcessorTest(ProcessorTesterMixin, unittest.TestCase):
47+
processor_class = SamProcessor
48+
4749
def setUp(self):
4850
self.tmpdirname = tempfile.mkdtemp()
4951
image_processor = SamImageProcessor()
@@ -56,11 +58,6 @@ def get_image_processor(self, **kwargs):
5658
def tearDown(self):
5759
shutil.rmtree(self.tmpdirname)
5860

59-
# Processor tester class can't use ProcessorTesterMixin atm because the processor is atypical e.g. only contains an image processor
60-
def prepare_image_inputs(self):
61-
"""This function prepares a list of PIL images."""
62-
return prepare_image_inputs()
63-
6461
def prepare_mask_inputs(self):
6562
"""This function prepares a list of PIL images, or a list of numpy arrays if one specifies numpify=True,
6663
or a list of PyTorch tensors if one specifies torchify=True.
@@ -69,6 +66,21 @@ def prepare_mask_inputs(self):
6966
mask_inputs = [Image.fromarray(x) for x in mask_inputs]
7067
return mask_inputs
7168

69+
def test_chat_template_save_loading(self):
70+
self.skipTest("SamProcessor does not have a tokenizer")
71+
72+
def test_image_processor_defaults_preserved_by_image_kwargs(self):
73+
self.skipTest("SamProcessor does not have a tokenizer")
74+
75+
def test_kwargs_overrides_default_image_processor_kwargs(self):
76+
self.skipTest("SamProcessor does not have a tokenizer")
77+
78+
def test_kwargs_overrides_default_tokenizer_kwargs(self):
79+
self.skipTest("SamProcessor does not have a tokenizer")
80+
81+
def test_tokenizer_defaults_preserved_by_kwargs(self):
82+
self.skipTest("SamProcessor does not have a tokenizer")
83+
7284
def test_save_load_pretrained_additional_features(self):
7385
processor = SamProcessor(image_processor=self.get_image_processor())
7486
processor.save_pretrained(self.tmpdirname)
@@ -152,7 +164,9 @@ def test_post_process_masks(self):
152164

153165
@require_vision
154166
@require_tf
155-
class TFSamProcessorTest(unittest.TestCase):
167+
class TFSamProcessorTest(ProcessorTesterMixin, unittest.TestCase):
168+
processor_class = SamProcessor
169+
156170
def setUp(self):
157171
self.tmpdirname = tempfile.mkdtemp()
158172
image_processor = SamImageProcessor()
@@ -165,10 +179,20 @@ def get_image_processor(self, **kwargs):
165179
def tearDown(self):
166180
shutil.rmtree(self.tmpdirname)
167181

168-
# Processor tester class can't use ProcessorTesterMixin as processor is atypical e.g. only contains an image processor and it assumes torch
169-
def prepare_image_inputs(self):
170-
"""This function prepares a list of PIL images."""
171-
return prepare_image_inputs()
182+
def test_chat_template_save_loading(self):
183+
self.skipTest("SamProcessor does not have a tokenizer")
184+
185+
def test_image_processor_defaults_preserved_by_image_kwargs(self):
186+
self.skipTest("SamProcessor does not have a tokenizer")
187+
188+
def test_kwargs_overrides_default_image_processor_kwargs(self):
189+
self.skipTest("SamProcessor does not have a tokenizer")
190+
191+
def test_kwargs_overrides_default_tokenizer_kwargs(self):
192+
self.skipTest("SamProcessor does not have a tokenizer")
193+
194+
def test_tokenizer_defaults_preserved_by_kwargs(self):
195+
self.skipTest("SamProcessor does not have a tokenizer")
172196

173197
def test_save_load_pretrained_additional_features(self):
174198
processor = SamProcessor(image_processor=self.get_image_processor())
@@ -235,7 +259,9 @@ def test_post_process_masks(self):
235259

236260
@require_vision
237261
@require_torchvision
238-
class SamProcessorEquivalenceTest(unittest.TestCase):
262+
class SamProcessorEquivalenceTest(ProcessorTesterMixin, unittest.TestCase):
263+
processor_class = SamProcessor
264+
239265
def setUp(self):
240266
self.tmpdirname = tempfile.mkdtemp()
241267
image_processor = SamImageProcessor()
@@ -248,10 +274,20 @@ def get_image_processor(self, **kwargs):
248274
def tearDown(self):
249275
shutil.rmtree(self.tmpdirname)
250276

251-
# Processor tester class can't use ProcessorTesterMixin atm because the processor is atypical e.g. only contains an image processor
252-
def prepare_image_inputs(self):
253-
"""This function prepares a list of PIL images."""
254-
return prepare_image_inputs()
277+
def test_chat_template_save_loading(self):
278+
self.skipTest("SamProcessor does not have a tokenizer")
279+
280+
def test_image_processor_defaults_preserved_by_image_kwargs(self):
281+
self.skipTest("SamProcessor does not have a tokenizer")
282+
283+
def test_kwargs_overrides_default_image_processor_kwargs(self):
284+
self.skipTest("SamProcessor does not have a tokenizer")
285+
286+
def test_kwargs_overrides_default_tokenizer_kwargs(self):
287+
self.skipTest("SamProcessor does not have a tokenizer")
288+
289+
def test_tokenizer_defaults_preserved_by_kwargs(self):
290+
self.skipTest("SamProcessor does not have a tokenizer")
255291

256292
@is_pt_tf_cross_test
257293
def test_post_process_masks_equivalence(self):

0 commit comments

Comments
 (0)
Please sign in to comment.