Fix image segmentation example - don't reopen image (#30481)
Fix image segmentation example - don't repoen image
This commit is contained in:
@@ -60,7 +60,7 @@ image
|
|||||||
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/segmentation_input.jpg" alt="Segmentation Input"/>
|
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/segmentation_input.jpg" alt="Segmentation Input"/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
We will use [nvidia/segformer-b1-finetuned-cityscapes-1024-1024](https://huggingface.co/nvidia/segformer-b1-finetuned-cityscapes-1024-1024).
|
We will use [nvidia/segformer-b1-finetuned-cityscapes-1024-1024](https://huggingface.co/nvidia/segformer-b1-finetuned-cityscapes-1024-1024).
|
||||||
|
|
||||||
```python
|
```python
|
||||||
semantic_segmentation = pipeline("image-segmentation", "nvidia/segformer-b1-finetuned-cityscapes-1024-1024")
|
semantic_segmentation = pipeline("image-segmentation", "nvidia/segformer-b1-finetuned-cityscapes-1024-1024")
|
||||||
@@ -68,7 +68,7 @@ results = semantic_segmentation(image)
|
|||||||
results
|
results
|
||||||
```
|
```
|
||||||
|
|
||||||
The segmentation pipeline output includes a mask for every predicted class.
|
The segmentation pipeline output includes a mask for every predicted class.
|
||||||
```bash
|
```bash
|
||||||
[{'score': None,
|
[{'score': None,
|
||||||
'label': 'road',
|
'label': 'road',
|
||||||
@@ -111,11 +111,11 @@ results[-1]["mask"]
|
|||||||
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/semantic_segmentation_output.png" alt="Semantic Segmentation Output"/>
|
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/semantic_segmentation_output.png" alt="Semantic Segmentation Output"/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
In instance segmentation, the goal is not to classify every pixel, but to predict a mask for **every instance of an object** in a given image. It works very similar to object detection, where there is a bounding box for every instance, there's a segmentation mask instead. We will use [facebook/mask2former-swin-large-cityscapes-instance](https://huggingface.co/facebook/mask2former-swin-large-cityscapes-instance) for this.
|
In instance segmentation, the goal is not to classify every pixel, but to predict a mask for **every instance of an object** in a given image. It works very similar to object detection, where there is a bounding box for every instance, there's a segmentation mask instead. We will use [facebook/mask2former-swin-large-cityscapes-instance](https://huggingface.co/facebook/mask2former-swin-large-cityscapes-instance) for this.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
instance_segmentation = pipeline("image-segmentation", "facebook/mask2former-swin-large-cityscapes-instance")
|
instance_segmentation = pipeline("image-segmentation", "facebook/mask2former-swin-large-cityscapes-instance")
|
||||||
results = instance_segmentation(Image.open(image))
|
results = instance_segmentation(image)
|
||||||
results
|
results
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -148,7 +148,7 @@ Panoptic segmentation combines semantic segmentation and instance segmentation,
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
panoptic_segmentation = pipeline("image-segmentation", "facebook/mask2former-swin-large-cityscapes-panoptic")
|
panoptic_segmentation = pipeline("image-segmentation", "facebook/mask2former-swin-large-cityscapes-panoptic")
|
||||||
results = panoptic_segmentation(Image.open(image))
|
results = panoptic_segmentation(image)
|
||||||
results
|
results
|
||||||
```
|
```
|
||||||
As you can see below, we have more classes. We will later illustrate to see that every pixel is classified into one of the classes.
|
As you can see below, we have more classes. We will later illustrate to see that every pixel is classified into one of the classes.
|
||||||
|
|||||||
Reference in New Issue
Block a user