nielsr HF staff commited on
Commit
5794372
1 Parent(s): a802057

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +18 -18
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
- >>> from transformers import MaskFormerFeatureExtractor, MaskFormerForInstanceSegmentation
33
- >>> from PIL import Image
34
- >>> import requests
35
-
36
- >>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
37
- >>> image = Image.open(requests.get(url, stream=True).raw)
38
- >>> feature_extractor = MaskFormerFeatureExtractor.from_pretrained("facebook/maskformer-swin-base-ade")
39
- >>> inputs = feature_extractor(images=image, return_tensors="pt")
40
-
41
- >>> model = MaskFormerForInstanceSegmentation.from_pretrained("facebook/maskformer-swin-base-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)[0]
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).