Spaces:
Runtime error
Runtime error
polejowska
commited on
Commit
•
2a32e11
1
Parent(s):
2a99234
Update visualization.py
Browse files- visualization.py +7 -11
visualization.py
CHANGED
@@ -7,15 +7,6 @@ from constants import COLORS
|
|
7 |
from utils import fig2img
|
8 |
|
9 |
|
10 |
-
def visualize_mask(mask, img, alpha=0.5):
|
11 |
-
mask = mask.cpu().squeeze().numpy()
|
12 |
-
img = img.cpu().squeeze().permute(1, 2, 0).numpy()
|
13 |
-
plt.imshow(img)
|
14 |
-
plt.imshow(mask, alpha=alpha)
|
15 |
-
plt.axis("off")
|
16 |
-
return fig2img(plt.gcf())
|
17 |
-
|
18 |
-
|
19 |
def visualize_prediction(
|
20 |
pil_img, output_dict, threshold=0.7, id2label=None, display_mask=False, mask=None
|
21 |
):
|
@@ -32,8 +23,13 @@ def visualize_prediction(
|
|
32 |
|
33 |
fig, ax = plt.subplots(figsize=(12, 12))
|
34 |
ax.imshow(pil_img)
|
35 |
-
if display_mask:
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
37 |
colors = COLORS * 100
|
38 |
for score, (xmin, ymin, xmax, ymax), label, color in zip(
|
39 |
scores, boxes, labels, colors
|
|
|
7 |
from utils import fig2img
|
8 |
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
def visualize_prediction(
|
11 |
pil_img, output_dict, threshold=0.7, id2label=None, display_mask=False, mask=None
|
12 |
):
|
|
|
23 |
|
24 |
fig, ax = plt.subplots(figsize=(12, 12))
|
25 |
ax.imshow(pil_img)
|
26 |
+
if display_mask and mask is not None:
|
27 |
+
# Create a new mask with white objects and black background
|
28 |
+
new_mask = np.zeros_like(mask)
|
29 |
+
new_mask[mask > 0] = 255
|
30 |
+
|
31 |
+
# Display the new mask as a semi-transparent overlay
|
32 |
+
ax.imshow(new_mask, alpha=0.5, cmap='gray')
|
33 |
colors = COLORS * 100
|
34 |
for score, (xmin, ymin, xmax, ymax), label, color in zip(
|
35 |
scores, boxes, labels, colors
|