Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/transformers/pipelines/image_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ 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")
>>> potential_words = classifier("https://huggingface.co/datasets/Narsil/image_dummy/raw/main/parrots.png")

>>> from transformers.testing_utils import nested_simplify

>>> nested_simplify(potential_words) # The scores might vary slightly across pytorch/tensorflow versions.
[{'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'}]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to use this, doctest will only compare the floats to the precision you write them. So the test will pass without using nested_simplify.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really ?? That's awesome, I can remove it in a lot of places then !

```

[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"`.

Expand Down