Instructions to use facebook/maskformer-swin-tiny-ade with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use facebook/maskformer-swin-tiny-ade with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-segmentation", model="facebook/maskformer-swin-tiny-ade")# pip install -U transformers accelerate # Load model directly from transformers import AutoImageProcessor, MaskFormerForInstanceSegmentation processor = AutoImageProcessor.from_pretrained("facebook/maskformer-swin-tiny-ade") model = MaskFormerForInstanceSegmentation.from_pretrained("facebook/maskformer-swin-tiny-ade", device_map="auto") - Inference
- Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,10 +1,15 @@
|
|
| 1 |
---
|
| 2 |
-
license:
|
| 3 |
tags:
|
| 4 |
- vision
|
| 5 |
- image-segmentation
|
| 6 |
datasets:
|
| 7 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
# MaskFormer
|
|
@@ -29,24 +34,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).
|
|
|
|
| 1 |
---
|
| 2 |
+
license: other
|
| 3 |
tags:
|
| 4 |
- vision
|
| 5 |
- image-segmentation
|
| 6 |
datasets:
|
| 7 |
+
- scene_parse_150
|
| 8 |
+
widget:
|
| 9 |
+
- src: https://huggingface.co/datasets/hf-internal-testing/fixtures_ade20k/resolve/main/ADE_val_00000001.jpg
|
| 10 |
+
example_title: House
|
| 11 |
+
- src: https://huggingface.co/datasets/hf-internal-testing/fixtures_ade20k/resolve/main/ADE_val_00000002.jpg
|
| 12 |
+
example_title: Castle
|
| 13 |
---
|
| 14 |
|
| 15 |
# MaskFormer
|
|
|
|
| 34 |
Here is how to use this model:
|
| 35 |
|
| 36 |
```python
|
| 37 |
+
from transformers import MaskFormerFeatureExtractor, 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 |
+
feature_extractor = MaskFormerFeatureExtractor.from_pretrained("facebook/maskformer-swin-tiny-ade")
|
| 44 |
+
inputs = feature_extractor(images=image, return_tensors="pt")
|
| 45 |
+
|
| 46 |
+
model = MaskFormerForInstanceSegmentation.from_pretrained("facebook/maskformer-swin-tiny-ade")
|
| 47 |
+
outputs = model(**inputs)
|
| 48 |
+
# model predicts class_queries_logits of shape `(batch_size, num_queries)`
|
| 49 |
+
# and masks_queries_logits of shape `(batch_size, num_queries, height, width)`
|
| 50 |
+
class_queries_logits = outputs.class_queries_logits
|
| 51 |
+
masks_queries_logits = outputs.masks_queries_logits
|
| 52 |
+
|
| 53 |
+
# you can pass them to feature_extractor for postprocessing
|
| 54 |
+
predicted_semantic_map = feature_extractor.post_process_semantic_segmentation(outputs, target_sizes=[image.size[::-1]])[0]
|
| 55 |
```
|
| 56 |
|
| 57 |
For more code examples, we refer to the [documentation](https://huggingface.co/docs/transformers/master/en/model_doc/maskformer).
|