Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -25,6 +25,14 @@ model_name_to_fn = {
|
|
25 |
|
26 |
|
27 |
### 3. Predict function ###
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
|
30 |
# Create predict function
|
@@ -67,8 +75,10 @@ def predict(image, model_name: str = "detr",) -> Tuple[Dict, float]:
|
|
67 |
# A tensor of shape (height, width) where each value denotes a segment id, filled with -1 if no segment is found
|
68 |
panoptic_seg = result[0]["segmentation"]
|
69 |
# Convert the tensor to PIL image
|
70 |
-
plt.
|
71 |
-
|
|
|
|
|
72 |
# output = PIL.Image.fromarray(panoptic_seg.cpu().numpy().astype('uint8')).convert('RGB')
|
73 |
|
74 |
elif model_name == "maskformer":
|
@@ -84,8 +94,10 @@ def predict(image, model_name: str = "detr",) -> Tuple[Dict, float]:
|
|
84 |
result = processor.post_process_panoptic_segmentation(outputs, target_sizes=[image.size[::-1]])[0]
|
85 |
# we refer to the demo notebooks for visualization (see "Resources" section in the MaskFormer docs)
|
86 |
predicted_panoptic_map = result["segmentation"]
|
87 |
-
plt.
|
88 |
-
|
|
|
|
|
89 |
# output = PIL.Image.fromarray(predicted_panoptic_map.cpu().numpy().astype('uint8')).convert('RGB')
|
90 |
|
91 |
# Calculate the prediction time
|
@@ -99,8 +111,8 @@ def predict(image, model_name: str = "detr",) -> Tuple[Dict, float]:
|
|
99 |
### 4. Gradio app ###
|
100 |
|
101 |
# Create title, description and article strings
|
102 |
-
title = "
|
103 |
-
description = "An Mutimodel
|
104 |
article = ""
|
105 |
|
106 |
# Create examples list from "examples/" directory
|
|
|
25 |
|
26 |
|
27 |
### 3. Predict function ###
|
28 |
+
def fig2img(fig):
|
29 |
+
"""Convert a Matplotlib figure to a PIL Image and return it"""
|
30 |
+
import io
|
31 |
+
buf = io.BytesIO()
|
32 |
+
fig.savefig(buf)
|
33 |
+
buf.seek(0)
|
34 |
+
img = Image.open(buf)
|
35 |
+
return img
|
36 |
|
37 |
|
38 |
# Create predict function
|
|
|
75 |
# A tensor of shape (height, width) where each value denotes a segment id, filled with -1 if no segment is found
|
76 |
panoptic_seg = result[0]["segmentation"]
|
77 |
# Convert the tensor to PIL image
|
78 |
+
plt.plot("predicted_panoptic_map.png", panoptic_seg, cmap="viridis")
|
79 |
+
fig = plt.gcf()
|
80 |
+
output = fig2img(fig)
|
81 |
+
# output = PIL.Image.open("predicted_panoptic_map.png")
|
82 |
# output = PIL.Image.fromarray(panoptic_seg.cpu().numpy().astype('uint8')).convert('RGB')
|
83 |
|
84 |
elif model_name == "maskformer":
|
|
|
94 |
result = processor.post_process_panoptic_segmentation(outputs, target_sizes=[image.size[::-1]])[0]
|
95 |
# we refer to the demo notebooks for visualization (see "Resources" section in the MaskFormer docs)
|
96 |
predicted_panoptic_map = result["segmentation"]
|
97 |
+
plt.plot("predicted_panoptic_map.png", predicted_panoptic_map, cmap="viridis")
|
98 |
+
fig = plt.gcf()
|
99 |
+
output = fig2img(fig)
|
100 |
+
# output = PIL.Image.open("predicted_panoptic_map.png")
|
101 |
# output = PIL.Image.fromarray(predicted_panoptic_map.cpu().numpy().astype('uint8')).convert('RGB')
|
102 |
|
103 |
# Calculate the prediction time
|
|
|
111 |
### 4. Gradio app ###
|
112 |
|
113 |
# Create title, description and article strings
|
114 |
+
title = "Segmentation Demo"
|
115 |
+
description = "An Mutimodel Segmentation Demo"
|
116 |
article = ""
|
117 |
|
118 |
# Create examples list from "examples/" directory
|