Spaces:
Runtime error
Runtime error
update
Browse files- demo.py +0 -110
- testv1.jpg +0 -0
- testv2.mp4 +0 -0
- testv3.jpeg +0 -0
demo.py
DELETED
@@ -1,110 +0,0 @@
|
|
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,
|
19 |
-
points_per_batch=points_per_batch,
|
20 |
-
min_area=min_area,
|
21 |
-
output_path="output.png",
|
22 |
-
show=False,
|
23 |
-
save=True,
|
24 |
-
)
|
25 |
-
return "output.png"
|
26 |
-
|
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
|
37 |
-
points_per_side=points_per_side,
|
38 |
-
points_per_batch=points_per_batch,
|
39 |
-
min_area=min_area,
|
40 |
-
output_path="output.mp4",
|
41 |
-
)
|
42 |
-
return "output.mp4"
|
43 |
-
|
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
|
60 |
-
input_point=input_point,
|
61 |
-
input_label=input_label,
|
62 |
-
input_box=input_box,
|
63 |
-
multimask_output=multimask_output,
|
64 |
-
random_color=random_color,
|
65 |
-
output_path="output.png",
|
66 |
-
show=False,
|
67 |
-
save=True,
|
68 |
-
)
|
69 |
-
return "output.png"
|
70 |
-
|
71 |
-
|
72 |
-
# For sahi sliced prediction
|
73 |
-
|
74 |
-
|
75 |
-
def sahi_autoseg_app(
|
76 |
-
image_path,
|
77 |
-
sam_model_type,
|
78 |
-
detection_model_type,
|
79 |
-
detection_model_path,
|
80 |
-
conf_th,
|
81 |
-
image_size,
|
82 |
-
slice_height,
|
83 |
-
slice_width,
|
84 |
-
overlap_height_ratio,
|
85 |
-
overlap_width_ratio,
|
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,
|
94 |
-
slice_height=slice_height,
|
95 |
-
slice_width=slice_width,
|
96 |
-
overlap_height_ratio=overlap_height_ratio,
|
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,
|
104 |
-
multimask_output=False,
|
105 |
-
random_color=False,
|
106 |
-
show=False,
|
107 |
-
save=True,
|
108 |
-
)
|
109 |
-
|
110 |
-
return "output.png"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
testv1.jpg
DELETED
Binary file (670 kB)
|
|
testv2.mp4
DELETED
Binary file (795 kB)
|
|
testv3.jpeg
DELETED
Binary file (106 kB)
|
|