Decorators for deprecation and named arguments validation (#30799)
* Fix do_reduce_labels for maskformer image processor * Deprecate reduce_labels in favor to do_reduce_labels * Deprecate reduce_labels in favor to do_reduce_labels (segformer) * Deprecate reduce_labels in favor to do_reduce_labels (oneformer) * Deprecate reduce_labels in favor to do_reduce_labels (maskformer) * Deprecate reduce_labels in favor to do_reduce_labels (mask2former) * Fix typo * Update mask2former test * fixup * Update segmentation examples * Update docs * Fixup * Imports fixup * Add deprecation decorator draft * Add deprecation decorator * Fixup * Add deprecate_kwarg decorator * Validate kwargs decorator * Kwargs validation (beit) * fixup * Kwargs validation (mask2former) * Kwargs validation (maskformer) * Kwargs validation (oneformer) * Kwargs validation (segformer) * Better message * Fix oneformer processor save-load test * Update src/transformers/utils/deprecation.py Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com> * Update src/transformers/utils/deprecation.py Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com> * Update src/transformers/utils/deprecation.py Co-authored-by: Pablo Montalvo <39954772+molbap@users.noreply.github.com> * Update src/transformers/utils/deprecation.py Co-authored-by: Pablo Montalvo <39954772+molbap@users.noreply.github.com> * Better handle classmethod warning * Fix typo, remove warn * Add header * Docs and `additional_message` * Move to filter decorator ot generic * Proper deprecation for semantic segm scripts * Add to __init__ and update import * Basic tests for filter decorator * Fix doc * Override `to_dict()` to pop depracated `_max_size` * Pop unused parameters * Fix trailing whitespace * Add test for deprecation * Add deprecation warning control parameter * Update generic test * Fixup deprecation tests * Introduce init service kwargs * Revert popping unused params * Revert oneformer test * Allow "metadata" to pass * Better docs * Fix test * Add notion in docstring * Fix notification for both names * Add func name to warning message * Fixup --------- Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com> Co-authored-by: Pablo Montalvo <39954772+molbap@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
4fa4dcb2be
commit
517df566f5
@@ -349,3 +349,16 @@ class OneFormerImageProcessingTest(ImageProcessingTestMixin, unittest.TestCase):
|
||||
image_processor = self.image_processing_class(**config_dict)
|
||||
|
||||
self.assertEqual(image_processor.metadata, metadata)
|
||||
|
||||
def test_removed_deprecated_kwargs(self):
|
||||
image_processor_dict = dict(self.image_processor_dict)
|
||||
image_processor_dict.pop("do_reduce_labels", None)
|
||||
image_processor_dict["reduce_labels"] = True
|
||||
|
||||
# test we are able to create the image processor with the deprecated kwargs
|
||||
image_processor = self.image_processing_class(**image_processor_dict)
|
||||
self.assertEqual(image_processor.do_reduce_labels, True)
|
||||
|
||||
# test we still support reduce_labels with config
|
||||
image_processor = self.image_processing_class.from_dict(image_processor_dict)
|
||||
self.assertEqual(image_processor.do_reduce_labels, True)
|
||||
|
||||
@@ -73,7 +73,7 @@ class OneFormerProcessorTester(unittest.TestCase):
|
||||
image_mean=[0.5, 0.5, 0.5],
|
||||
image_std=[0.5, 0.5, 0.5],
|
||||
num_labels=10,
|
||||
reduce_labels=False,
|
||||
do_reduce_labels=False,
|
||||
ignore_index=255,
|
||||
max_seq_length=77,
|
||||
task_seq_length=77,
|
||||
@@ -105,7 +105,7 @@ class OneFormerProcessorTester(unittest.TestCase):
|
||||
self.height = 3
|
||||
self.width = 4
|
||||
self.num_labels = num_labels
|
||||
self.reduce_labels = reduce_labels
|
||||
self.do_reduce_labels = do_reduce_labels
|
||||
self.ignore_index = ignore_index
|
||||
|
||||
def prepare_processor_dict(self):
|
||||
@@ -116,7 +116,7 @@ class OneFormerProcessorTester(unittest.TestCase):
|
||||
"image_mean": self.image_mean,
|
||||
"image_std": self.image_std,
|
||||
"num_labels": self.num_labels,
|
||||
"reduce_labels": self.reduce_labels,
|
||||
"do_reduce_labels": self.do_reduce_labels,
|
||||
"ignore_index": self.ignore_index,
|
||||
"class_info_file": self.class_info_file,
|
||||
"metadata": self.metadata,
|
||||
@@ -465,7 +465,7 @@ class OneFormerProcessingTest(unittest.TestCase):
|
||||
panoptic_map2, inst2class2 = create_panoptic_map(annotation2, segments_info2)
|
||||
|
||||
image_processor = OneFormerImageProcessor(
|
||||
reduce_labels=True,
|
||||
do_reduce_labels=True,
|
||||
ignore_index=0,
|
||||
size=(512, 512),
|
||||
class_info_file="ade20k_panoptic.json",
|
||||
@@ -553,7 +553,7 @@ class OneFormerProcessingTest(unittest.TestCase):
|
||||
panoptic_map2, inst2class2 = create_panoptic_map(annotation2, segments_info2)
|
||||
|
||||
image_processor = OneFormerImageProcessor(
|
||||
reduce_labels=True,
|
||||
do_reduce_labels=True,
|
||||
ignore_index=0,
|
||||
size=(512, 512),
|
||||
class_info_file="ade20k_panoptic.json",
|
||||
@@ -641,7 +641,7 @@ class OneFormerProcessingTest(unittest.TestCase):
|
||||
panoptic_map2, inst2class2 = create_panoptic_map(annotation2, segments_info2)
|
||||
|
||||
image_processor = OneFormerImageProcessor(
|
||||
reduce_labels=True,
|
||||
do_reduce_labels=True,
|
||||
ignore_index=0,
|
||||
size=(512, 512),
|
||||
class_info_file="ade20k_panoptic.json",
|
||||
@@ -710,7 +710,7 @@ class OneFormerProcessingTest(unittest.TestCase):
|
||||
|
||||
def test_post_process_semantic_segmentation(self):
|
||||
image_processor = OneFormerImageProcessor(
|
||||
reduce_labels=True,
|
||||
do_reduce_labels=True,
|
||||
ignore_index=0,
|
||||
size=(512, 512),
|
||||
class_info_file="ade20k_panoptic.json",
|
||||
@@ -744,7 +744,7 @@ class OneFormerProcessingTest(unittest.TestCase):
|
||||
|
||||
def test_post_process_instance_segmentation(self):
|
||||
image_processor = OneFormerImageProcessor(
|
||||
reduce_labels=True,
|
||||
do_reduce_labels=True,
|
||||
ignore_index=0,
|
||||
size=(512, 512),
|
||||
class_info_file="ade20k_panoptic.json",
|
||||
@@ -770,7 +770,7 @@ class OneFormerProcessingTest(unittest.TestCase):
|
||||
|
||||
def test_post_process_panoptic_segmentation(self):
|
||||
image_processor = OneFormerImageProcessor(
|
||||
reduce_labels=True,
|
||||
do_reduce_labels=True,
|
||||
ignore_index=0,
|
||||
size=(512, 512),
|
||||
class_info_file="ade20k_panoptic.json",
|
||||
|
||||
Reference in New Issue
Block a user