From fdef980e508efd52098c1392ea3cc3fb6ae62f83 Mon Sep 17 00:00:00 2001 From: Olivier Dehaene Date: Fri, 2 Sep 2022 10:12:56 +0200 Subject: [PATCH] Fix naming issue with ImageToText pipeline --- docs/source/en/main_classes/pipelines.mdx | 6 +++--- src/transformers/__init__.py | 4 ++-- src/transformers/pipelines/__init__.py | 6 +++--- .../{image2text_generation.py => image_to_text.py} | 9 ++++----- ...generation.py => test_pipelines_image_to_text.py} | 12 ++++++------ 5 files changed, 18 insertions(+), 19 deletions(-) rename src/transformers/pipelines/{image2text_generation.py => image_to_text.py} (90%) rename tests/pipelines/{test_pipelines_image2text_generation.py => test_pipelines_image_to_text.py} (90%) diff --git a/docs/source/en/main_classes/pipelines.mdx b/docs/source/en/main_classes/pipelines.mdx index 2ab730ef553821..b2de7e048dd5aa 100644 --- a/docs/source/en/main_classes/pipelines.mdx +++ b/docs/source/en/main_classes/pipelines.mdx @@ -29,7 +29,7 @@ There are two categories of pipeline abstractions to be aware about: - [`FillMaskPipeline`] - [`ImageClassificationPipeline`] - [`ImageSegmentationPipeline`] - - [`Image2TextGenerationPipeline`] + - [`ImageToTextPipeline`] - [`ObjectDetectionPipeline`] - [`QuestionAnsweringPipeline`] - [`SummarizationPipeline`] @@ -366,9 +366,9 @@ That should enable you to do all the custom code you want. - __call__ - all -### Image2TextGenerationPipeline +### ImageToTextPipeline -[[autodoc]] Image2TextGenerationPipeline +[[autodoc]] ImageToTextPipeline - __call__ - all diff --git a/src/transformers/__init__.py b/src/transformers/__init__.py index 98e7a7317d3c43..b952ff085f4a5f 100755 --- a/src/transformers/__init__.py +++ b/src/transformers/__init__.py @@ -384,9 +384,9 @@ "CsvPipelineDataFormat", "FeatureExtractionPipeline", "FillMaskPipeline", - "Image2TextGenerationPipeline", "ImageClassificationPipeline", "ImageSegmentationPipeline", + "ImageToTextPipeline", "JsonPipelineDataFormat", "NerPipeline", "ObjectDetectionPipeline", @@ -3192,9 +3192,9 @@ CsvPipelineDataFormat, FeatureExtractionPipeline, FillMaskPipeline, - Image2TextGenerationPipeline, ImageClassificationPipeline, ImageSegmentationPipeline, + ImageToTextPipeline, JsonPipelineDataFormat, NerPipeline, ObjectDetectionPipeline, diff --git a/src/transformers/pipelines/__init__.py b/src/transformers/pipelines/__init__.py index 0f29b4a971531d..ee7dee57c0e9d2 100755 --- a/src/transformers/pipelines/__init__.py +++ b/src/transformers/pipelines/__init__.py @@ -53,9 +53,9 @@ from .conversational import Conversation, ConversationalPipeline from .feature_extraction import FeatureExtractionPipeline from .fill_mask import FillMaskPipeline -from .image2text_generation import Image2TextGenerationPipeline from .image_classification import ImageClassificationPipeline from .image_segmentation import ImageSegmentationPipeline +from .image_to_text import ImageToTextPipeline from .object_detection import ObjectDetectionPipeline from .question_answering import QuestionAnsweringArgumentHandler, QuestionAnsweringPipeline from .table_question_answering import TableQuestionAnsweringArgumentHandler, TableQuestionAnsweringPipeline @@ -305,8 +305,8 @@ "default": {"model": {"pt": ("facebook/detr-resnet-50-panoptic", "fc15262")}}, "type": "image", }, - "image2text-generation": { - "impl": Image2TextGenerationPipeline, + "image-to-text": { + "impl": ImageToTextPipeline, "tf": (TFAutoModelForVision2Seq,) if is_tf_available() else (), "pt": (AutoModelForVision2Seq,) if is_torch_available() else (), "default": { diff --git a/src/transformers/pipelines/image2text_generation.py b/src/transformers/pipelines/image_to_text.py similarity index 90% rename from src/transformers/pipelines/image2text_generation.py rename to src/transformers/pipelines/image_to_text.py index 22dad12a924cad..934525533ef8cb 100644 --- a/src/transformers/pipelines/image2text_generation.py +++ b/src/transformers/pipelines/image_to_text.py @@ -26,13 +26,12 @@ @add_end_docstrings(PIPELINE_INIT_ARGS) -class Image2TextGenerationPipeline(Pipeline): +class ImageToTextPipeline(Pipeline): """ - Image2Text Generation pipeline using a `AutoModelForVision2Seq`. This pipeline predicts a caption for a given - image. + Image To Text pipeline using a `AutoModelForVision2Seq`. This pipeline predicts a caption for a given image. - This image to text generation pipeline can currently be loaded from pipeline() using the following task identifier: - "image2text-generation". + This image to text pipeline can currently be loaded from pipeline() using the following task identifier: + "image-to-text". See the list of available models on [huggingface.co/models](https://huggingface.co/models?pipeline_tag=image-to-text). diff --git a/tests/pipelines/test_pipelines_image2text_generation.py b/tests/pipelines/test_pipelines_image_to_text.py similarity index 90% rename from tests/pipelines/test_pipelines_image2text_generation.py rename to tests/pipelines/test_pipelines_image_to_text.py index ce0a3d64faea57..897c3b2e47250d 100644 --- a/tests/pipelines/test_pipelines_image2text_generation.py +++ b/tests/pipelines/test_pipelines_image_to_text.py @@ -33,12 +33,12 @@ def open(*args, **kwargs): @is_pipeline_test @require_vision -class Image2TextGenerationPipelineTests(unittest.TestCase, metaclass=PipelineTestCaseMeta): +class ImageToTextPipelineTests(unittest.TestCase, metaclass=PipelineTestCaseMeta): model_mapping = MODEL_FOR_VISION_2_SEQ_MAPPING tf_model_mapping = TF_MODEL_FOR_VISION_2_SEQ_MAPPING def get_test_pipeline(self, model, tokenizer, feature_extractor): - pipe = pipeline("image2text-generation", model=model, tokenizer=tokenizer, feature_extractor=feature_extractor) + pipe = pipeline("image-to-text", model=model, tokenizer=tokenizer, feature_extractor=feature_extractor) examples = [ Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"), "./tests/fixtures/tests_samples/COCO/000000039769.png", @@ -57,7 +57,7 @@ def run_pipeline_test(self, pipe, examples): @require_tf def test_small_model_tf(self): - pipe = pipeline("image2text-generation", model="hf-internal-testing/tiny-random-vit-gpt2") + pipe = pipeline("image-to-text", model="hf-internal-testing/tiny-random-vit-gpt2") image = "./tests/fixtures/tests_samples/COCO/000000039769.png" outputs = pipe(image) @@ -104,7 +104,7 @@ def test_small_model_tf(self): @require_torch def test_small_model_pt(self): - pipe = pipeline("image2text-generation", model="hf-internal-testing/tiny-random-vit-gpt2") + pipe = pipeline("image-to-text", model="hf-internal-testing/tiny-random-vit-gpt2") image = "./tests/fixtures/tests_samples/COCO/000000039769.png" outputs = pipe(image) @@ -137,7 +137,7 @@ def test_small_model_pt(self): @slow @require_torch def test_large_model_pt(self): - pipe = pipeline("image2text-generation", model="ydshieh/vit-gpt2-coco-en") + pipe = pipeline("image-to-text", model="ydshieh/vit-gpt2-coco-en") image = "./tests/fixtures/tests_samples/COCO/000000039769.png" outputs = pipe(image) @@ -155,7 +155,7 @@ def test_large_model_pt(self): @slow @require_tf def test_large_model_tf(self): - pipe = pipeline("image2text-generation", model="ydshieh/vit-gpt2-coco-en") + pipe = pipeline("image-to-text", model="ydshieh/vit-gpt2-coco-en") image = "./tests/fixtures/tests_samples/COCO/000000039769.png" outputs = pipe(image)