Update old existing feature extractor references (#24552)
* Update old existing feature extractor references * Typo * Apply suggestions from code review * Apply suggestions from code review * Apply suggestions from code review * Address comments from review - update 'feature extractor' Co-authored by: Yih-Dar <2521628+ydshieh@users.noreply.github.com>
This commit is contained in:
@@ -42,7 +42,7 @@ if is_torch_available():
|
||||
if is_vision_available():
|
||||
from PIL import Image
|
||||
|
||||
from transformers import SegformerFeatureExtractor
|
||||
from transformers import SegformerImageProcessor
|
||||
|
||||
|
||||
class SegformerConfigTester(ConfigTester):
|
||||
@@ -365,7 +365,7 @@ class SegformerModelIntegrationTest(unittest.TestCase):
|
||||
@slow
|
||||
def test_inference_image_segmentation_ade(self):
|
||||
# only resize + normalize
|
||||
feature_extractor = SegformerFeatureExtractor(
|
||||
image_processor = SegformerImageProcessor(
|
||||
image_scale=(512, 512), keep_ratio=False, align=False, do_random_crop=False
|
||||
)
|
||||
model = SegformerForSemanticSegmentation.from_pretrained("nvidia/segformer-b0-finetuned-ade-512-512").to(
|
||||
@@ -373,7 +373,7 @@ class SegformerModelIntegrationTest(unittest.TestCase):
|
||||
)
|
||||
|
||||
image = prepare_img()
|
||||
encoded_inputs = feature_extractor(images=image, return_tensors="pt")
|
||||
encoded_inputs = image_processor(images=image, return_tensors="pt")
|
||||
pixel_values = encoded_inputs.pixel_values.to(torch_device)
|
||||
|
||||
with torch.no_grad():
|
||||
@@ -394,7 +394,7 @@ class SegformerModelIntegrationTest(unittest.TestCase):
|
||||
@slow
|
||||
def test_inference_image_segmentation_city(self):
|
||||
# only resize + normalize
|
||||
feature_extractor = SegformerFeatureExtractor(
|
||||
image_processor = SegformerImageProcessor(
|
||||
image_scale=(512, 512), keep_ratio=False, align=False, do_random_crop=False
|
||||
)
|
||||
model = SegformerForSemanticSegmentation.from_pretrained(
|
||||
@@ -402,7 +402,7 @@ class SegformerModelIntegrationTest(unittest.TestCase):
|
||||
).to(torch_device)
|
||||
|
||||
image = prepare_img()
|
||||
encoded_inputs = feature_extractor(images=image, return_tensors="pt")
|
||||
encoded_inputs = image_processor(images=image, return_tensors="pt")
|
||||
pixel_values = encoded_inputs.pixel_values.to(torch_device)
|
||||
|
||||
with torch.no_grad():
|
||||
@@ -423,7 +423,7 @@ class SegformerModelIntegrationTest(unittest.TestCase):
|
||||
@slow
|
||||
def test_post_processing_semantic_segmentation(self):
|
||||
# only resize + normalize
|
||||
feature_extractor = SegformerFeatureExtractor(
|
||||
image_processor = SegformerImageProcessor(
|
||||
image_scale=(512, 512), keep_ratio=False, align=False, do_random_crop=False
|
||||
)
|
||||
model = SegformerForSemanticSegmentation.from_pretrained("nvidia/segformer-b0-finetuned-ade-512-512").to(
|
||||
@@ -431,7 +431,7 @@ class SegformerModelIntegrationTest(unittest.TestCase):
|
||||
)
|
||||
|
||||
image = prepare_img()
|
||||
encoded_inputs = feature_extractor(images=image, return_tensors="pt")
|
||||
encoded_inputs = image_processor(images=image, return_tensors="pt")
|
||||
pixel_values = encoded_inputs.pixel_values.to(torch_device)
|
||||
|
||||
with torch.no_grad():
|
||||
@@ -439,10 +439,10 @@ class SegformerModelIntegrationTest(unittest.TestCase):
|
||||
|
||||
outputs.logits = outputs.logits.detach().cpu()
|
||||
|
||||
segmentation = feature_extractor.post_process_semantic_segmentation(outputs=outputs, target_sizes=[(500, 300)])
|
||||
segmentation = image_processor.post_process_semantic_segmentation(outputs=outputs, target_sizes=[(500, 300)])
|
||||
expected_shape = torch.Size((500, 300))
|
||||
self.assertEqual(segmentation[0].shape, expected_shape)
|
||||
|
||||
segmentation = feature_extractor.post_process_semantic_segmentation(outputs=outputs)
|
||||
segmentation = image_processor.post_process_semantic_segmentation(outputs=outputs)
|
||||
expected_shape = torch.Size((128, 128))
|
||||
self.assertEqual(segmentation[0].shape, expected_shape)
|
||||
|
||||
@@ -39,7 +39,7 @@ if is_tf_available():
|
||||
if is_vision_available():
|
||||
from PIL import Image
|
||||
|
||||
from transformers import SegformerFeatureExtractor
|
||||
from transformers import SegformerImageProcessor
|
||||
|
||||
|
||||
class TFSegformerConfigTester(ConfigTester):
|
||||
@@ -454,13 +454,13 @@ class TFSegformerModelIntegrationTest(unittest.TestCase):
|
||||
@slow
|
||||
def test_inference_image_segmentation_ade(self):
|
||||
# only resize + normalize
|
||||
feature_extractor = SegformerFeatureExtractor(
|
||||
image_processor = SegformerImageProcessor(
|
||||
image_scale=(512, 512), keep_ratio=False, align=False, do_random_crop=False
|
||||
)
|
||||
model = TFSegformerForSemanticSegmentation.from_pretrained("nvidia/segformer-b0-finetuned-ade-512-512")
|
||||
|
||||
image = prepare_img()
|
||||
encoded_inputs = feature_extractor(images=image, return_tensors="tf")
|
||||
encoded_inputs = image_processor(images=image, return_tensors="tf")
|
||||
pixel_values = encoded_inputs.pixel_values
|
||||
|
||||
outputs = model(pixel_values, training=False)
|
||||
@@ -480,7 +480,7 @@ class TFSegformerModelIntegrationTest(unittest.TestCase):
|
||||
@slow
|
||||
def test_inference_image_segmentation_city(self):
|
||||
# only resize + normalize
|
||||
feature_extractor = SegformerFeatureExtractor(
|
||||
image_processor = SegformerImageProcessor(
|
||||
image_scale=(512, 512), keep_ratio=False, align=False, do_random_crop=False
|
||||
)
|
||||
model = TFSegformerForSemanticSegmentation.from_pretrained(
|
||||
@@ -488,7 +488,7 @@ class TFSegformerModelIntegrationTest(unittest.TestCase):
|
||||
)
|
||||
|
||||
image = prepare_img()
|
||||
encoded_inputs = feature_extractor(images=image, return_tensors="tf")
|
||||
encoded_inputs = image_processor(images=image, return_tensors="tf")
|
||||
pixel_values = encoded_inputs.pixel_values
|
||||
|
||||
outputs = model(pixel_values, training=False)
|
||||
|
||||
Reference in New Issue
Block a user