Fix snippet
#2
by
merve
HF staff
- opened
README.md
CHANGED
@@ -39,7 +39,7 @@ Here is how to use this model:
|
|
39 |
from transformers import OneFormerProcessor, OneFormerForUniversalSegmentation
|
40 |
from PIL import Image
|
41 |
import requests
|
42 |
-
url = "https://huggingface.co/datasets/shi-labs/oneformer_demo/
|
43 |
image = Image.open(requests.get(url, stream=True).raw)
|
44 |
|
45 |
# Loading a single model for all three tasks
|
@@ -50,19 +50,19 @@ model = OneFormerForUniversalSegmentation.from_pretrained("shi-labs/oneformer_ad
|
|
50 |
semantic_inputs = processor(images=image, task_inputs=["semantic"], return_tensors="pt")
|
51 |
semantic_outputs = model(**semantic_inputs)
|
52 |
# pass through image_processor for postprocessing
|
53 |
-
predicted_semantic_map = processor.post_process_semantic_segmentation(
|
54 |
|
55 |
# Instance Segmentation
|
56 |
instance_inputs = processor(images=image, task_inputs=["instance"], return_tensors="pt")
|
57 |
instance_outputs = model(**instance_inputs)
|
58 |
# pass through image_processor for postprocessing
|
59 |
-
predicted_instance_map = processor.post_process_instance_segmentation(
|
60 |
|
61 |
# Panoptic Segmentation
|
62 |
panoptic_inputs = processor(images=image, task_inputs=["panoptic"], return_tensors="pt")
|
63 |
panoptic_outputs = model(**panoptic_inputs)
|
64 |
# pass through image_processor for postprocessing
|
65 |
-
predicted_semantic_map = processor.post_process_panoptic_segmentation(
|
66 |
```
|
67 |
|
68 |
For more examples, please refer to the [documentation](https://huggingface.co/docs/transformers/master/en/model_doc/oneformer).
|
|
|
39 |
from transformers import OneFormerProcessor, OneFormerForUniversalSegmentation
|
40 |
from PIL import Image
|
41 |
import requests
|
42 |
+
url = "https://huggingface.co/datasets/shi-labs/oneformer_demo/resolve/main/ade20k.jpeg"
|
43 |
image = Image.open(requests.get(url, stream=True).raw)
|
44 |
|
45 |
# Loading a single model for all three tasks
|
|
|
50 |
semantic_inputs = processor(images=image, task_inputs=["semantic"], return_tensors="pt")
|
51 |
semantic_outputs = model(**semantic_inputs)
|
52 |
# pass through image_processor for postprocessing
|
53 |
+
predicted_semantic_map = processor.post_process_semantic_segmentation(semantic_outputs, target_sizes=[image.size[::-1]])[0]
|
54 |
|
55 |
# Instance Segmentation
|
56 |
instance_inputs = processor(images=image, task_inputs=["instance"], return_tensors="pt")
|
57 |
instance_outputs = model(**instance_inputs)
|
58 |
# pass through image_processor for postprocessing
|
59 |
+
predicted_instance_map = processor.post_process_instance_segmentation(instance_outputs, target_sizes=[image.size[::-1]])[0]["segmentation"]
|
60 |
|
61 |
# Panoptic Segmentation
|
62 |
panoptic_inputs = processor(images=image, task_inputs=["panoptic"], return_tensors="pt")
|
63 |
panoptic_outputs = model(**panoptic_inputs)
|
64 |
# pass through image_processor for postprocessing
|
65 |
+
predicted_semantic_map = processor.post_process_panoptic_segmentation(panoptic_outputs, target_sizes=[image.size[::-1]])[0]["segmentation"]
|
66 |
```
|
67 |
|
68 |
For more examples, please refer to the [documentation](https://huggingface.co/docs/transformers/master/en/model_doc/oneformer).
|