"...git@developer.sourcefind.cn:chenpangpang/transformers.git" did not exist on "2d27900b5d74a84b4c6b95950fd26c9d794b2d57"
Unverified Commit e2bd7f80 authored by amyeroberts's avatar amyeroberts Committed by GitHub
Browse files

Update tests: replace feature extractor tests with image processor (#20768)



* Update imports and test fetcher

* Revert but keep test fetcher update

* Fix imports

* Fix all imports

* Replace fe with ip names

* Add generate kwargs to `AutomaticSpeechRecognitionPipeline` (#20952)

* Add generate kwargs to AutomaticSpeechRecognitionPipeline

* Add test for generation kwargs

* Update image processor parameters if creating with kwargs (#20866)

* Update parameters if creating with kwargs

* Shallow copy to prevent mutating input

* Pass all args in constructor dict - warnings in init

* Fix typo

* Rename tester class

* Rebase and tidy up

* Fixup

* Use ImageProcessingSavingTestMixin

* Update property ref in tests

* Update property ref in tests

* Update recently merged in models

* Small fix
Co-authored-by: default avatarbofeng huang <bofenghuang7@gmail.com>
parent 354ea443
...@@ -23,8 +23,7 @@ from huggingface_hub import hf_hub_download ...@@ -23,8 +23,7 @@ from huggingface_hub import hf_hub_download
from transformers.testing_utils import require_torch, require_vision from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available from transformers.utils import is_torch_available, is_vision_available
from ...test_feature_extraction_common import FeatureExtractionSavingTestMixin from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs
from ...test_image_processing_common import prepare_image_inputs
if is_torch_available(): if is_torch_available():
...@@ -100,7 +99,7 @@ class OneFormerImageProcessorTester(unittest.TestCase): ...@@ -100,7 +99,7 @@ class OneFormerImageProcessorTester(unittest.TestCase):
self.do_reduce_labels = do_reduce_labels self.do_reduce_labels = do_reduce_labels
self.ignore_index = ignore_index self.ignore_index = ignore_index
def prepare_feat_extract_dict(self): def prepare_image_processor_dict(self):
return { return {
"do_resize": self.do_resize, "do_resize": self.do_resize,
"size": self.size, "size": self.size,
...@@ -156,20 +155,20 @@ class OneFormerImageProcessorTester(unittest.TestCase): ...@@ -156,20 +155,20 @@ class OneFormerImageProcessorTester(unittest.TestCase):
@require_torch @require_torch
@require_vision @require_vision
class OneFormerImageProcessingTest(FeatureExtractionSavingTestMixin, unittest.TestCase): class OneFormerImageProcessingTest(ImageProcessingSavingTestMixin, unittest.TestCase):
image_processing_class = OneFormerImageProcessor if (is_vision_available() and is_torch_available()) else None image_processing_class = OneFormerImageProcessor if (is_vision_available() and is_torch_available()) else None
# only for test_feat_extracttion_common.test_feat_extract_to_json_string # only for test_image_processing_common.test_image_proc_to_json_string
feature_extraction_class = image_processing_class image_processing_class = image_processing_class
def setUp(self): def setUp(self):
self.image_processing_tester = OneFormerImageProcessorTester(self) self.image_processing_tester = OneFormerImageProcessorTester(self)
@property @property
def feat_extract_dict(self): def image_processor_dict(self):
return self.image_processing_tester.prepare_feat_extract_dict() return self.image_processing_tester.prepare_image_processor_dict()
def test_feat_extract_properties(self): def test_image_proc_properties(self):
image_processor = self.image_processing_class(**self.feat_extract_dict) image_processor = self.image_processing_class(**self.image_processor_dict)
self.assertTrue(hasattr(image_processor, "image_mean")) self.assertTrue(hasattr(image_processor, "image_mean"))
self.assertTrue(hasattr(image_processor, "image_std")) self.assertTrue(hasattr(image_processor, "image_std"))
self.assertTrue(hasattr(image_processor, "do_normalize")) self.assertTrue(hasattr(image_processor, "do_normalize"))
...@@ -187,7 +186,7 @@ class OneFormerImageProcessingTest(FeatureExtractionSavingTestMixin, unittest.Te ...@@ -187,7 +186,7 @@ class OneFormerImageProcessingTest(FeatureExtractionSavingTestMixin, unittest.Te
def test_call_pil(self): def test_call_pil(self):
# Initialize image_processor # Initialize image_processor
image_processor = self.image_processing_class(**self.feat_extract_dict) image_processor = self.image_processing_class(**self.image_processor_dict)
# create random PIL images # create random PIL images
image_inputs = prepare_image_inputs(self.image_processing_tester, equal_resolution=False) image_inputs = prepare_image_inputs(self.image_processing_tester, equal_resolution=False)
for image in image_inputs: for image in image_inputs:
...@@ -221,7 +220,7 @@ class OneFormerImageProcessingTest(FeatureExtractionSavingTestMixin, unittest.Te ...@@ -221,7 +220,7 @@ class OneFormerImageProcessingTest(FeatureExtractionSavingTestMixin, unittest.Te
def test_call_numpy(self): def test_call_numpy(self):
# Initialize image_processor # Initialize image_processor
image_processor = self.image_processing_class(**self.feat_extract_dict) image_processor = self.image_processing_class(**self.image_processor_dict)
# create random numpy tensors # create random numpy tensors
image_inputs = prepare_image_inputs(self.image_processing_tester, equal_resolution=False, numpify=True) image_inputs = prepare_image_inputs(self.image_processing_tester, equal_resolution=False, numpify=True)
for image in image_inputs: for image in image_inputs:
...@@ -255,7 +254,7 @@ class OneFormerImageProcessingTest(FeatureExtractionSavingTestMixin, unittest.Te ...@@ -255,7 +254,7 @@ class OneFormerImageProcessingTest(FeatureExtractionSavingTestMixin, unittest.Te
def test_call_pytorch(self): def test_call_pytorch(self):
# Initialize image_processor # Initialize image_processor
image_processor = self.image_processing_class(**self.feat_extract_dict) image_processor = self.image_processing_class(**self.image_processor_dict)
# create random PyTorch tensors # create random PyTorch tensors
image_inputs = prepare_image_inputs(self.image_processing_tester, equal_resolution=False, torchify=True) image_inputs = prepare_image_inputs(self.image_processing_tester, equal_resolution=False, torchify=True)
for image in image_inputs: for image in image_inputs:
...@@ -289,7 +288,7 @@ class OneFormerImageProcessingTest(FeatureExtractionSavingTestMixin, unittest.Te ...@@ -289,7 +288,7 @@ class OneFormerImageProcessingTest(FeatureExtractionSavingTestMixin, unittest.Te
def test_equivalence_pad_and_create_pixel_mask(self): def test_equivalence_pad_and_create_pixel_mask(self):
# Initialize image_processors # Initialize image_processors
image_processor_1 = self.image_processing_class(**self.feat_extract_dict) image_processor_1 = self.image_processing_class(**self.image_processor_dict)
image_processor_2 = self.image_processing_class( image_processor_2 = self.image_processing_class(
do_resize=False, do_resize=False,
do_normalize=False, do_normalize=False,
...@@ -320,7 +319,7 @@ class OneFormerImageProcessingTest(FeatureExtractionSavingTestMixin, unittest.Te ...@@ -320,7 +319,7 @@ class OneFormerImageProcessingTest(FeatureExtractionSavingTestMixin, unittest.Te
def comm_get_image_processor_inputs( def comm_get_image_processor_inputs(
self, with_segmentation_maps=False, is_instance_map=False, segmentation_type="np" self, with_segmentation_maps=False, is_instance_map=False, segmentation_type="np"
): ):
image_processor = self.image_processing_class(**self.feat_extract_dict) image_processor = self.image_processing_class(**self.image_processor_dict)
# prepare image and target # prepare image and target
num_labels = self.image_processing_tester.num_labels num_labels = self.image_processing_tester.num_labels
annotations = None annotations = None
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment