Spaces:
Runtime error
Runtime error
migrating SAM2 space from T4 to ZERO
Browse files- app.py +12 -2
- requirements.txt +1 -0
- utils/models.py +2 -2
app.py
CHANGED
@@ -9,6 +9,7 @@ from gradio_image_prompter import ImagePrompter
|
|
9 |
|
10 |
from utils.models import load_models, CHECKPOINT_NAMES, MODE_NAMES, \
|
11 |
MASK_GENERATION_MODE, BOX_PROMPT_MODE
|
|
|
12 |
|
13 |
MARKDOWN = """
|
14 |
# Segment Anything Model 2 🔥
|
@@ -37,11 +38,20 @@ EXAMPLES = [
|
|
37 |
["tiny", MASK_GENERATION_MODE, "https://media.roboflow.com/notebooks/examples/dog-4.jpeg", None],
|
38 |
]
|
39 |
|
40 |
-
DEVICE = torch.device('cuda'
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
MASK_ANNOTATOR = sv.MaskAnnotator(color_lookup=sv.ColorLookup.INDEX)
|
42 |
IMAGE_PREDICTORS, MASK_GENERATORS = load_models(device=DEVICE)
|
43 |
|
44 |
|
|
|
|
|
|
|
45 |
def process(
|
46 |
checkpoint_dropdown,
|
47 |
mode_dropdown,
|
@@ -147,4 +157,4 @@ with gr.Blocks() as demo:
|
|
147 |
outputs=[image_output_component]
|
148 |
)
|
149 |
|
150 |
-
demo.launch(debug=False, show_error=True
|
|
|
9 |
|
10 |
from utils.models import load_models, CHECKPOINT_NAMES, MODE_NAMES, \
|
11 |
MASK_GENERATION_MODE, BOX_PROMPT_MODE
|
12 |
+
import spaces
|
13 |
|
14 |
MARKDOWN = """
|
15 |
# Segment Anything Model 2 🔥
|
|
|
38 |
["tiny", MASK_GENERATION_MODE, "https://media.roboflow.com/notebooks/examples/dog-4.jpeg", None],
|
39 |
]
|
40 |
|
41 |
+
DEVICE = torch.device('cuda')
|
42 |
+
|
43 |
+
torch.autocast(device_type="cuda", dtype=torch.bfloat16).__enter__()
|
44 |
+
if torch.cuda.get_device_properties(0).major >= 8:
|
45 |
+
torch.backends.cuda.matmul.allow_tf32 = True
|
46 |
+
torch.backends.cudnn.allow_tf32 = True
|
47 |
+
|
48 |
MASK_ANNOTATOR = sv.MaskAnnotator(color_lookup=sv.ColorLookup.INDEX)
|
49 |
IMAGE_PREDICTORS, MASK_GENERATORS = load_models(device=DEVICE)
|
50 |
|
51 |
|
52 |
+
@spaces.GPU
|
53 |
+
@torch.inference_mode()
|
54 |
+
@torch.autocast(device_type="cuda", dtype=torch.bfloat16)
|
55 |
def process(
|
56 |
checkpoint_dropdown,
|
57 |
mode_dropdown,
|
|
|
157 |
outputs=[image_output_component]
|
158 |
)
|
159 |
|
160 |
+
demo.launch(debug=False, show_error=True)
|
requirements.txt
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
samv2
|
2 |
gradio
|
3 |
supervision
|
|
|
1 |
+
spaces
|
2 |
samv2
|
3 |
gradio
|
4 |
supervision
|
utils/models.py
CHANGED
@@ -6,9 +6,9 @@ from sam2.build_sam import build_sam2
|
|
6 |
from sam2.sam2_image_predictor import SAM2ImagePredictor
|
7 |
|
8 |
BOX_PROMPT_MODE = "box prompt"
|
|
|
9 |
MASK_GENERATION_MODE = "mask generation"
|
10 |
-
|
11 |
-
MODE_NAMES = [BOX_PROMPT_MODE, MASK_GENERATION_MODE]
|
12 |
|
13 |
CHECKPOINT_NAMES = ["tiny", "small", "base_plus", "large"]
|
14 |
CHECKPOINTS = {
|
|
|
6 |
from sam2.sam2_image_predictor import SAM2ImagePredictor
|
7 |
|
8 |
BOX_PROMPT_MODE = "box prompt"
|
9 |
+
POINT_PROMPT_MODE = "point prompt"
|
10 |
MASK_GENERATION_MODE = "mask generation"
|
11 |
+
MODE_NAMES = [BOX_PROMPT_MODE, POINT_PROMPT_MODE, MASK_GENERATION_MODE]
|
|
|
12 |
|
13 |
CHECKPOINT_NAMES = ["tiny", "small", "base_plus", "large"]
|
14 |
CHECKPOINTS = {
|