Spaces:
Runtime error
Runtime error
Update demo.py
Browse files
demo.py
CHANGED
@@ -1,9 +1,18 @@
|
|
1 |
-
from metaseg import
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
# For image
|
4 |
|
5 |
-
|
|
|
|
|
|
|
6 |
SegAutoMaskPredictor().image_predict(
|
|
|
7 |
source=image_path,
|
8 |
model_type=model_type, # vit_l, vit_h, vit_b
|
9 |
points_per_side=points_per_side,
|
@@ -18,7 +27,10 @@ def automask_image_app(image_path, model_type, points_per_side, points_per_batch
|
|
18 |
|
19 |
# For video
|
20 |
|
21 |
-
|
|
|
|
|
|
|
22 |
SegAutoMaskPredictor().video_predict(
|
23 |
source=video_path,
|
24 |
model_type=model_type, # vit_l, vit_h, vit_b
|
@@ -32,7 +44,16 @@ def automask_video_app(video_path, model_type, points_per_side, points_per_batch
|
|
32 |
|
33 |
# For manuel box and point selection
|
34 |
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
SegManualMaskPredictor().image_predict(
|
37 |
source=image_path,
|
38 |
model_type=model_type, # vit_l, vit_h, vit_b
|
@@ -50,6 +71,7 @@ def manual_app(image_path, model_type, input_point, input_label, input_box, mult
|
|
50 |
|
51 |
# For sahi sliced prediction
|
52 |
|
|
|
53 |
def sahi_autoseg_app(
|
54 |
image_path,
|
55 |
sam_model_type,
|
@@ -64,7 +86,8 @@ def sahi_autoseg_app(
|
|
64 |
):
|
65 |
boxes = sahi_sliced_predict(
|
66 |
image_path=image_path,
|
67 |
-
|
|
|
68 |
detection_model_path=detection_model_path,
|
69 |
conf_th=conf_th,
|
70 |
image_size=image_size,
|
@@ -74,7 +97,7 @@ def sahi_autoseg_app(
|
|
74 |
overlap_width_ratio=overlap_width_ratio,
|
75 |
)
|
76 |
|
77 |
-
SahiAutoSegmentation().
|
78 |
source=image_path,
|
79 |
model_type=sam_model_type,
|
80 |
input_box=boxes,
|
@@ -83,5 +106,5 @@ def sahi_autoseg_app(
|
|
83 |
show=False,
|
84 |
save=True,
|
85 |
)
|
86 |
-
|
87 |
return "output.png"
|
|
|
1 |
+
from metaseg import (
|
2 |
+
SahiAutoSegmentation,
|
3 |
+
SegAutoMaskPredictor,
|
4 |
+
SegManualMaskPredictor,
|
5 |
+
sahi_sliced_predict,
|
6 |
+
)
|
7 |
|
8 |
# For image
|
9 |
|
10 |
+
|
11 |
+
def automask_image_app(
|
12 |
+
image_path, model_type, points_per_side, points_per_batch, min_area
|
13 |
+
):
|
14 |
SegAutoMaskPredictor().image_predict(
|
15 |
+
|
16 |
source=image_path,
|
17 |
model_type=model_type, # vit_l, vit_h, vit_b
|
18 |
points_per_side=points_per_side,
|
|
|
27 |
|
28 |
# For video
|
29 |
|
30 |
+
|
31 |
+
def automask_video_app(
|
32 |
+
video_path, model_type, points_per_side, points_per_batch, min_area
|
33 |
+
):
|
34 |
SegAutoMaskPredictor().video_predict(
|
35 |
source=video_path,
|
36 |
model_type=model_type, # vit_l, vit_h, vit_b
|
|
|
44 |
|
45 |
# For manuel box and point selection
|
46 |
|
47 |
+
|
48 |
+
def manual_app(
|
49 |
+
image_path,
|
50 |
+
model_type,
|
51 |
+
input_point,
|
52 |
+
input_label,
|
53 |
+
input_box,
|
54 |
+
multimask_output,
|
55 |
+
random_color,
|
56 |
+
):
|
57 |
SegManualMaskPredictor().image_predict(
|
58 |
source=image_path,
|
59 |
model_type=model_type, # vit_l, vit_h, vit_b
|
|
|
71 |
|
72 |
# For sahi sliced prediction
|
73 |
|
74 |
+
|
75 |
def sahi_autoseg_app(
|
76 |
image_path,
|
77 |
sam_model_type,
|
|
|
86 |
):
|
87 |
boxes = sahi_sliced_predict(
|
88 |
image_path=image_path,
|
89 |
+
# yolov8, detectron2, mmdetection, torchvision
|
90 |
+
detection_model_type=detection_model_type,
|
91 |
detection_model_path=detection_model_path,
|
92 |
conf_th=conf_th,
|
93 |
image_size=image_size,
|
|
|
97 |
overlap_width_ratio=overlap_width_ratio,
|
98 |
)
|
99 |
|
100 |
+
SahiAutoSegmentation().image_predict(
|
101 |
source=image_path,
|
102 |
model_type=sam_model_type,
|
103 |
input_box=boxes,
|
|
|
106 |
show=False,
|
107 |
save=True,
|
108 |
)
|
109 |
+
|
110 |
return "output.png"
|