Update README.md
Browse files
README.md
CHANGED
|
@@ -34,14 +34,15 @@ fine-tuned versions on a task that interests you.
|
|
| 34 |
Here is how to use this model:
|
| 35 |
|
| 36 |
```python
|
| 37 |
-
from transformers import
|
| 38 |
from PIL import Image
|
| 39 |
import requests
|
| 40 |
|
| 41 |
url = "https://huggingface.co/datasets/hf-internal-testing/fixtures_ade20k/resolve/main/ADE_val_00000001.jpg"
|
| 42 |
image = Image.open(requests.get(url, stream=True).raw)
|
| 43 |
-
|
| 44 |
-
|
|
|
|
| 45 |
|
| 46 |
model = MaskFormerForInstanceSegmentation.from_pretrained("facebook/maskformer-swin-large-ade")
|
| 47 |
outputs = model(**inputs)
|
|
@@ -50,9 +51,9 @@ outputs = model(**inputs)
|
|
| 50 |
class_queries_logits = outputs.class_queries_logits
|
| 51 |
masks_queries_logits = outputs.masks_queries_logits
|
| 52 |
|
| 53 |
-
# you can pass them to
|
| 54 |
# we refer to the demo notebooks for visualization (see "Resources" section in the MaskFormer docs)
|
| 55 |
-
predicted_semantic_map =
|
| 56 |
```
|
| 57 |
|
| 58 |
For more code examples, we refer to the [documentation](https://huggingface.co/docs/transformers/master/en/model_doc/maskformer).
|
|
|
|
| 34 |
Here is how to use this model:
|
| 35 |
|
| 36 |
```python
|
| 37 |
+
from transformers import MaskFormerImageProcessor, MaskFormerForInstanceSegmentation
|
| 38 |
from PIL import Image
|
| 39 |
import requests
|
| 40 |
|
| 41 |
url = "https://huggingface.co/datasets/hf-internal-testing/fixtures_ade20k/resolve/main/ADE_val_00000001.jpg"
|
| 42 |
image = Image.open(requests.get(url, stream=True).raw)
|
| 43 |
+
|
| 44 |
+
processor = MaskFormerImageProcessor.from_pretrained("facebook/maskformer-swin-large-ade")
|
| 45 |
+
inputs = processor(images=image, return_tensors="pt")
|
| 46 |
|
| 47 |
model = MaskFormerForInstanceSegmentation.from_pretrained("facebook/maskformer-swin-large-ade")
|
| 48 |
outputs = model(**inputs)
|
|
|
|
| 51 |
class_queries_logits = outputs.class_queries_logits
|
| 52 |
masks_queries_logits = outputs.masks_queries_logits
|
| 53 |
|
| 54 |
+
# you can pass them to processor for postprocessing
|
| 55 |
# we refer to the demo notebooks for visualization (see "Resources" section in the MaskFormer docs)
|
| 56 |
+
predicted_semantic_map = processor.post_process_semantic_segmentation(outputs, target_sizes=[image.size[::-1]])[0]
|
| 57 |
```
|
| 58 |
|
| 59 |
For more code examples, we refer to the [documentation](https://huggingface.co/docs/transformers/master/en/model_doc/maskformer).
|