Spaces:
Runtime error
Runtime error
JuanLozada97
commited on
Commit
•
ed18f8f
1
Parent(s):
8c8790d
Update app.py
Browse files
app.py
CHANGED
@@ -27,8 +27,22 @@ medsam_model = create_sam_model(model_type,checkpoint,device)
|
|
27 |
mask_generator = SamAutomaticMaskGenerator(medsam_model)
|
28 |
|
29 |
# 3.Predict fn
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
|
|
32 |
def predict(img) -> Tuple[Dict, float]:
|
33 |
"""Transforms and performs a prediction on img and returns prediction and time taken.
|
34 |
"""
|
|
|
27 |
mask_generator = SamAutomaticMaskGenerator(medsam_model)
|
28 |
|
29 |
# 3.Predict fn
|
30 |
+
def show_anns(anns):
|
31 |
+
if len(anns) == 0:
|
32 |
+
return
|
33 |
+
sorted_anns = sorted(anns, key=(lambda x: x['area']), reverse=True)
|
34 |
+
ax = plt.gca()
|
35 |
+
ax.set_autoscale_on(False)
|
36 |
+
|
37 |
+
img = np.ones((sorted_anns[0]['segmentation'].shape[0], sorted_anns[0]['segmentation'].shape[1], 4))
|
38 |
+
img[:,:,3] = 0
|
39 |
+
for ann in sorted_anns:
|
40 |
+
m = ann['segmentation']
|
41 |
+
color_mask = np.concatenate([np.random.random(3), [0.35]])
|
42 |
+
img[m] = color_mask
|
43 |
+
ax.imshow(img)
|
44 |
|
45 |
+
@torch.no_grad()
|
46 |
def predict(img) -> Tuple[Dict, float]:
|
47 |
"""Transforms and performs a prediction on img and returns prediction and time taken.
|
48 |
"""
|