Skip to content

Commit 553be69

Browse files
NarsilMagnus Pierrau
authored andcommitted
Adding doctest for image-segmentation pipeline. (huggingface#20256)
* Adding doctest for `image-segmentation` pipeline. * Fixup.
1 parent 19cc6bb commit 553be69

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/transformers/pipelines/image_segmentation.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,30 @@ class ImageSegmentationPipeline(Pipeline):
3232
Image segmentation pipeline using any `AutoModelForXXXSegmentation`. This pipeline predicts masks of objects and
3333
their classes.
3434
35+
Example:
36+
37+
```python
38+
>>> from transformers import pipeline
39+
40+
>>> segmenter = pipeline(model="facebook/detr-resnet-50-panoptic")
41+
>>> segments = segmenter("https://huggingface.co/datasets/Narsil/image_dummy/raw/main/parrots.png")
42+
>>> len(segments)
43+
2
44+
45+
>>> segments[0]["label"]
46+
'bird'
47+
48+
>>> segments[1]["label"]
49+
'bird'
50+
51+
>>> type(segments[0]["mask"]) # This is a black and white mask showing where is the bird on the original image.
52+
<class 'PIL.Image.Image'>
53+
54+
>>> segments[0]["mask"].size
55+
(768, 512)
56+
```
57+
58+
3559
This image segmentation pipeline can currently be loaded from [`pipeline`] using the following task identifier:
3660
`"image-segmentation"`.
3761

0 commit comments

Comments
 (0)