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: bofeng huang <bofenghuang7@gmail.com>
This commit is contained in:
@@ -23,8 +23,7 @@ from huggingface_hub import hf_hub_download
|
||||
from transformers.testing_utils import require_torch, require_vision
|
||||
from transformers.utils import is_torch_available, is_vision_available
|
||||
|
||||
from ...test_feature_extraction_common import FeatureExtractionSavingTestMixin
|
||||
from ...test_image_processing_common import prepare_image_inputs
|
||||
from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs
|
||||
|
||||
|
||||
if is_torch_available():
|
||||
@@ -100,7 +99,7 @@ class OneFormerImageProcessorTester(unittest.TestCase):
|
||||
self.do_reduce_labels = do_reduce_labels
|
||||
self.ignore_index = ignore_index
|
||||
|
||||
def prepare_feat_extract_dict(self):
|
||||
def prepare_image_processor_dict(self):
|
||||
return {
|
||||
"do_resize": self.do_resize,
|
||||
"size": self.size,
|
||||
@@ -156,20 +155,20 @@ class OneFormerImageProcessorTester(unittest.TestCase):
|
||||
|
||||
@require_torch
|
||||
@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
|
||||
# only for test_feat_extracttion_common.test_feat_extract_to_json_string
|
||||
feature_extraction_class = image_processing_class
|
||||
# only for test_image_processing_common.test_image_proc_to_json_string
|
||||
image_processing_class = image_processing_class
|
||||
|
||||
def setUp(self):
|
||||
self.image_processing_tester = OneFormerImageProcessorTester(self)
|
||||
|
||||
@property
|
||||
def feat_extract_dict(self):
|
||||
return self.image_processing_tester.prepare_feat_extract_dict()
|
||||
def image_processor_dict(self):
|
||||
return self.image_processing_tester.prepare_image_processor_dict()
|
||||
|
||||
def test_feat_extract_properties(self):
|
||||
image_processor = self.image_processing_class(**self.feat_extract_dict)
|
||||
def test_image_proc_properties(self):
|
||||
image_processor = self.image_processing_class(**self.image_processor_dict)
|
||||
self.assertTrue(hasattr(image_processor, "image_mean"))
|
||||
self.assertTrue(hasattr(image_processor, "image_std"))
|
||||
self.assertTrue(hasattr(image_processor, "do_normalize"))
|
||||
@@ -187,7 +186,7 @@ class OneFormerImageProcessingTest(FeatureExtractionSavingTestMixin, unittest.Te
|
||||
|
||||
def test_call_pil(self):
|
||||
# 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
|
||||
image_inputs = prepare_image_inputs(self.image_processing_tester, equal_resolution=False)
|
||||
for image in image_inputs:
|
||||
@@ -221,7 +220,7 @@ class OneFormerImageProcessingTest(FeatureExtractionSavingTestMixin, unittest.Te
|
||||
|
||||
def test_call_numpy(self):
|
||||
# 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
|
||||
image_inputs = prepare_image_inputs(self.image_processing_tester, equal_resolution=False, numpify=True)
|
||||
for image in image_inputs:
|
||||
@@ -255,7 +254,7 @@ class OneFormerImageProcessingTest(FeatureExtractionSavingTestMixin, unittest.Te
|
||||
|
||||
def test_call_pytorch(self):
|
||||
# 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
|
||||
image_inputs = prepare_image_inputs(self.image_processing_tester, equal_resolution=False, torchify=True)
|
||||
for image in image_inputs:
|
||||
@@ -289,7 +288,7 @@ class OneFormerImageProcessingTest(FeatureExtractionSavingTestMixin, unittest.Te
|
||||
|
||||
def test_equivalence_pad_and_create_pixel_mask(self):
|
||||
# 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(
|
||||
do_resize=False,
|
||||
do_normalize=False,
|
||||
@@ -320,7 +319,7 @@ class OneFormerImageProcessingTest(FeatureExtractionSavingTestMixin, unittest.Te
|
||||
def comm_get_image_processor_inputs(
|
||||
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
|
||||
num_labels = self.image_processing_tester.num_labels
|
||||
annotations = None
|
||||
|
||||
Reference in New Issue
Block a user