Update README.md
Browse files
README.md
CHANGED
@@ -1,67 +1,65 @@
|
|
1 |
-
---
|
2 |
-
license: other
|
3 |
-
tags:
|
4 |
-
- vision
|
5 |
-
- image-segmentation
|
6 |
-
datasets:
|
7 |
-
- coco
|
8 |
-
widget:
|
9 |
-
- src: http://images.cocodataset.org/val2017/000000039769.jpg
|
10 |
-
example_title: Cats
|
11 |
-
- src: http://images.cocodataset.org/val2017/000000039770.jpg
|
12 |
-
example_title: Castle
|
13 |
-
---
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
```
|
66 |
-
|
67 |
-
For more code examples, we refer to the [documentation](https://huggingface.co/docs/transformers/master/en/model_doc/mask2former).
|
|
|
1 |
+
---
|
2 |
+
license: other
|
3 |
+
tags:
|
4 |
+
- vision
|
5 |
+
- image-segmentation
|
6 |
+
datasets:
|
7 |
+
- coco
|
8 |
+
widget:
|
9 |
+
- src: http://images.cocodataset.org/val2017/000000039769.jpg
|
10 |
+
example_title: Cats
|
11 |
+
- src: http://images.cocodataset.org/val2017/000000039770.jpg
|
12 |
+
example_title: Castle
|
13 |
+
---
|
14 |
+
|
15 |
+
|
16 |
+
|
17 |
+
### How to use
|
18 |
+
|
19 |
+
Here is how to use this model:
|
20 |
+
|
21 |
+
```python
|
22 |
+
from transformers import AutoImageProcessor, Mask2FormerForUniversalSegmentation
|
23 |
+
from PIL import Image
|
24 |
+
import matplotlib.pyplot as plt
|
25 |
+
|
26 |
+
# Load the processor and model
|
27 |
+
model_name = "saninmohammedn/mask2former-deployment"
|
28 |
+
processor = AutoImageProcessor.from_pretrained(model_name)
|
29 |
+
model = Mask2FormerForUniversalSegmentation.from_pretrained(model_name)
|
30 |
+
|
31 |
+
# Load an input image
|
32 |
+
image_path = "your_image.jpg" # Replace with your image path
|
33 |
+
image = Image.open(image_path).convert("RGB")
|
34 |
+
|
35 |
+
# Prepare the image for the model
|
36 |
+
inputs = processor(images=image, return_tensors="pt")
|
37 |
+
|
38 |
+
# Perform inference
|
39 |
+
with torch.no_grad():
|
40 |
+
outputs = model(**inputs)
|
41 |
+
|
42 |
+
# Post-process the predicted segmentation map
|
43 |
+
predicted_map = processor.post_process_semantic_segmentation(
|
44 |
+
outputs, target_sizes=[image.size[::-1]]
|
45 |
+
)[0].cpu().numpy()
|
46 |
+
|
47 |
+
# Visualize the input and predicted segmentation map
|
48 |
+
plt.figure(figsize=(10, 5))
|
49 |
+
|
50 |
+
# Display original image
|
51 |
+
plt.subplot(1, 2, 1)
|
52 |
+
plt.imshow(image)
|
53 |
+
plt.title("Original Image")
|
54 |
+
plt.axis("off")
|
55 |
+
|
56 |
+
# Display predicted segmentation map
|
57 |
+
plt.subplot(1, 2, 2)
|
58 |
+
plt.imshow(predicted_map, cmap="jet")
|
59 |
+
plt.title("Predicted Segmentation Map")
|
60 |
+
plt.axis("off")
|
61 |
+
|
62 |
+
plt.tight_layout()
|
63 |
+
plt.show()
|
64 |
+
|
65 |
+
```
|
|
|
|