From 291c17f6087093bb892697049424f90ce7340c58 Mon Sep 17 00:00:00 2001 From: Nicolas Patry Date: Wed, 16 Nov 2022 17:09:57 +0100 Subject: [PATCH] Adding doctest example for `image-classification` pipeline. (#20254) * adding doctest example for `image-classification` pipeline. * Remove nested simplify. --- src/transformers/pipelines/image_classification.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/transformers/pipelines/image_classification.py b/src/transformers/pipelines/image_classification.py index e180aaf8cc..5f448d829b 100644 --- a/src/transformers/pipelines/image_classification.py +++ b/src/transformers/pipelines/image_classification.py @@ -34,6 +34,18 @@ class ImageClassificationPipeline(Pipeline): Image classification pipeline using any `AutoModelForImageClassification`. This pipeline predicts the class of an image. + Example: + + ```python + >>> from transformers import pipeline + + >>> classifier = pipeline(model="microsoft/beit-base-patch16-224-pt22k-ft22k") + >>> classifier("https://huggingface.co/datasets/Narsil/image_dummy/raw/main/parrots.png") + [{'score': 0.442, 'label': 'macaw'}, {'score': 0.088, 'label': 'popinjay'}, {'score': 0.075, 'label': 'parrot'}, {'score': 0.073, 'label': 'parodist, lampooner'}, {'score': 0.046, 'label': 'poll, poll_parrot'}] + ``` + + [Learn more about the basics of using a pipeline in the [pipeline tutorial]](../pipeline_tutorial) + This image classification pipeline can currently be loaded from [`pipeline`] using the following task identifier: `"image-classification"`.