Update README.md
Browse files
README.md
CHANGED
@@ -29,24 +29,24 @@ fine-tuned versions on a task that interests you.
|
|
29 |
Here is how to use this model:
|
30 |
|
31 |
```python
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
```
|
51 |
|
52 |
For more code examples, we refer to the [documentation](https://huggingface.co/docs/transformers/master/en/model_doc/maskformer).
|
|
|
29 |
Here is how to use this model:
|
30 |
|
31 |
```python
|
32 |
+
from transformers import MaskFormerFeatureExtractor, MaskFormerForInstanceSegmentation
|
33 |
+
from PIL import Image
|
34 |
+
import requests
|
35 |
+
|
36 |
+
url = "https://huggingface.co/datasets/hf-internal-testing/fixtures_ade20k/resolve/main/ADE_val_00000001.jpg"
|
37 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
38 |
+
feature_extractor = MaskFormerFeatureExtractor.from_pretrained("facebook/maskformer-swin-large-ade")
|
39 |
+
inputs = feature_extractor(images=image, return_tensors="pt")
|
40 |
+
|
41 |
+
model = MaskFormerForInstanceSegmentation.from_pretrained("facebook/maskformer-swin-large-ade")
|
42 |
+
outputs = model(**inputs)
|
43 |
+
# model predicts class_queries_logits of shape `(batch_size, num_queries)`
|
44 |
+
# and masks_queries_logits of shape `(batch_size, num_queries, height, width)`
|
45 |
+
class_queries_logits = outputs.class_queries_logits
|
46 |
+
masks_queries_logits = outputs.masks_queries_logits
|
47 |
+
|
48 |
+
# you can pass them to feature_extractor for postprocessing
|
49 |
+
predicted_semantic_map = feature_extractor.post_process_semantic_segmentation(outputs, target_sizes=[image.size[::-1]])[0]
|
50 |
```
|
51 |
|
52 |
For more code examples, we refer to the [documentation](https://huggingface.co/docs/transformers/master/en/model_doc/maskformer).
|