praeclarumjj3
commited on
Commit
•
95748da
1
Parent(s):
5556700
Update Readme
Browse files
README.md
CHANGED
@@ -35,33 +35,33 @@ You can use this particular checkpoint for semantic, instance and panoptic segme
|
|
35 |
Here is how to use this model:
|
36 |
|
37 |
```python
|
38 |
-
from transformers import
|
39 |
from PIL import Image
|
40 |
import requests
|
41 |
url = "https://huggingface.co/datasets/shi-labs/oneformer_demo/blob/main/ade20k.jpeg"
|
42 |
image = Image.open(requests.get(url, stream=True).raw)
|
43 |
|
44 |
# Loading a single model for all three tasks
|
45 |
-
|
46 |
model = OneFormerForUniversalSegmentation.from_pretrained("shi-labs/oneformer_ade20k_swin_tiny")
|
47 |
|
48 |
# Semantic Segmentation
|
49 |
-
semantic_inputs =
|
50 |
semantic_outputs = model(**semantic_inputs)
|
51 |
-
# pass through
|
52 |
-
predicted_semantic_map =
|
53 |
|
54 |
# Instance Segmentation
|
55 |
-
instance_inputs =
|
56 |
instance_outputs = model(**instance_inputs)
|
57 |
-
# pass through
|
58 |
-
predicted_instance_map =
|
59 |
|
60 |
# Panoptic Segmentation
|
61 |
-
panoptic_inputs =
|
62 |
panoptic_outputs = model(**panoptic_inputs)
|
63 |
-
# pass through
|
64 |
-
predicted_semantic_map =
|
65 |
```
|
66 |
|
67 |
For more examples, please refer to the [documentation](https://huggingface.co/docs/transformers/master/en/model_doc/oneformer).
|
|
|
35 |
Here is how to use this model:
|
36 |
|
37 |
```python
|
38 |
+
from transformers import OneFormerImageProcessor, OneFormerForUniversalSegmentation
|
39 |
from PIL import Image
|
40 |
import requests
|
41 |
url = "https://huggingface.co/datasets/shi-labs/oneformer_demo/blob/main/ade20k.jpeg"
|
42 |
image = Image.open(requests.get(url, stream=True).raw)
|
43 |
|
44 |
# Loading a single model for all three tasks
|
45 |
+
image_processor = OneFormerImageProcessor.from_pretrained("shi-labs/oneformer_ade20k_swin_tiny")
|
46 |
model = OneFormerForUniversalSegmentation.from_pretrained("shi-labs/oneformer_ade20k_swin_tiny")
|
47 |
|
48 |
# Semantic Segmentation
|
49 |
+
semantic_inputs = image_processor(images=image, ["semantic"] return_tensors="pt")
|
50 |
semantic_outputs = model(**semantic_inputs)
|
51 |
+
# pass through image_processor for postprocessing
|
52 |
+
predicted_semantic_map = image_processor.post_process_semantic_segmentation(outputs, target_sizes=[image.size[::-1]])[0]
|
53 |
|
54 |
# Instance Segmentation
|
55 |
+
instance_inputs = image_processor(images=image, ["instance"] return_tensors="pt")
|
56 |
instance_outputs = model(**instance_inputs)
|
57 |
+
# pass through image_processor for postprocessing
|
58 |
+
predicted_instance_map = image_processor.post_process_instance_segmentation(outputs, target_sizes=[image.size[::-1]])[0]["segmentation"]
|
59 |
|
60 |
# Panoptic Segmentation
|
61 |
+
panoptic_inputs = image_processor(images=image, ["panoptic"] return_tensors="pt")
|
62 |
panoptic_outputs = model(**panoptic_inputs)
|
63 |
+
# pass through image_processor for postprocessing
|
64 |
+
predicted_semantic_map = image_processor.post_process_panoptic_segmentation(outputs, target_sizes=[image.size[::-1]])[0]["segmentation"]
|
65 |
```
|
66 |
|
67 |
For more examples, please refer to the [documentation](https://huggingface.co/docs/transformers/master/en/model_doc/oneformer).
|