Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
4af3ab2
1
Parent(s):
b4e40a2
keep only edgetam
Browse files
README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
emoji: 👀
|
| 4 |
colorFrom: purple
|
| 5 |
colorTo: indigo
|
|
@@ -8,7 +8,7 @@ sdk_version: 5.47.2
|
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: apache-2.0
|
| 11 |
-
short_description: Segment
|
| 12 |
---
|
| 13 |
|
| 14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: EdgeTAM Video Tracking
|
| 3 |
emoji: 👀
|
| 4 |
colorFrom: purple
|
| 5 |
colorTo: indigo
|
|
|
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: apache-2.0
|
| 11 |
+
short_description: Segment and track any objects with EdgeTAM
|
| 12 |
---
|
| 13 |
|
| 14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
CHANGED
|
@@ -122,7 +122,7 @@ class AppState:
|
|
| 122 |
self.pending_box_start_obj_id: int | None = None
|
| 123 |
self.is_switching_model: bool = False
|
| 124 |
# Model selection
|
| 125 |
-
self.model_repo_key: str = "
|
| 126 |
self.model_repo_id: str | None = None
|
| 127 |
self.session_repo_id: str | None = None
|
| 128 |
|
|
@@ -135,14 +135,8 @@ class AppState:
|
|
| 135 |
|
| 136 |
|
| 137 |
def _model_repo_from_key(key: str) -> str:
|
| 138 |
-
mapping = {
|
| 139 |
-
|
| 140 |
-
"small": "facebook/sam2.1-hiera-small",
|
| 141 |
-
"base_plus": "facebook/sam2.1-hiera-base-plus",
|
| 142 |
-
"large": "facebook/sam2.1-hiera-large",
|
| 143 |
-
"EdgeTAM": "yonigozlan/EdgeTAM-hf",
|
| 144 |
-
}
|
| 145 |
-
return mapping.get(key, mapping["base_plus"])
|
| 146 |
|
| 147 |
|
| 148 |
def load_model_if_needed(GLOBAL_STATE: gr.State) -> tuple[AutoModel, Sam2VideoProcessor, str, torch.dtype]:
|
|
@@ -533,13 +527,13 @@ def reset_session(GLOBAL_STATE: gr.State) -> tuple[AppState, Image.Image, int, i
|
|
| 533 |
|
| 534 |
theme = Soft(primary_hue="blue", secondary_hue="rose", neutral_hue="slate")
|
| 535 |
|
| 536 |
-
with gr.Blocks(title="
|
| 537 |
GLOBAL_STATE = gr.State(AppState())
|
| 538 |
|
| 539 |
gr.Markdown(
|
| 540 |
"""
|
| 541 |
-
###
|
| 542 |
-
Segment and track objects across a video with
|
| 543 |
"""
|
| 544 |
)
|
| 545 |
with gr.Row():
|
|
@@ -548,7 +542,6 @@ with gr.Blocks(title="SAM2 Video (Transformers) - Interactive Segmentation", the
|
|
| 548 |
"""
|
| 549 |
**Quick start**
|
| 550 |
- **Load a video**: Upload your own or pick an example below.
|
| 551 |
-
- **Checkpoint**: Tiny / Small / Base+ / Large (trade speed vs. accuracy).
|
| 552 |
- **Points mode**: Select an Object ID and point label (positive/negative), then click the frame to add guidance. You can add **multiple points per object** and define **multiple objects** across frames.
|
| 553 |
- **Boxes mode**: Click two opposite corners to draw a box. Old inputs for that object are cleared automatically.
|
| 554 |
"""
|
|
@@ -560,19 +553,13 @@ with gr.Blocks(title="SAM2 Video (Transformers) - Interactive Segmentation", the
|
|
| 560 |
- **Preview**: Use the slider to navigate frames and see the current masks.
|
| 561 |
- **Propagate**: Click “Propagate across video” to track all defined objects through the entire video. The preview follows progress periodically to keep things responsive.
|
| 562 |
- **Export**: Render an MP4 for smooth playback using the original video FPS.
|
| 563 |
-
- **Note**: More info on the Hugging Face 🤗 Transformers implementation of
|
| 564 |
"""
|
| 565 |
)
|
| 566 |
|
| 567 |
with gr.Row():
|
| 568 |
with gr.Column(scale=1):
|
| 569 |
video_in = gr.Video(label="Upload video", sources=["upload", "webcam"], interactive=True)
|
| 570 |
-
ckpt_radio = gr.Radio(
|
| 571 |
-
choices=["tiny", "small", "base_plus", "large", "EdgeTAM"],
|
| 572 |
-
value="tiny",
|
| 573 |
-
label="SAM2.1 checkpoint",
|
| 574 |
-
)
|
| 575 |
-
ckpt_progress = gr.Markdown(visible=False)
|
| 576 |
load_status = gr.Markdown(visible=True)
|
| 577 |
reset_btn = gr.Button("Reset Session", variant="secondary")
|
| 578 |
with gr.Column(scale=2):
|
|
@@ -628,26 +615,6 @@ with gr.Blocks(title="SAM2 Video (Transformers) - Interactive Segmentation", the
|
|
| 628 |
render_btn = gr.Button("Render MP4 for smooth playback", variant="primary")
|
| 629 |
playback_video = gr.Video(label="Rendered Playback", interactive=False)
|
| 630 |
|
| 631 |
-
def _on_ckpt_change(s: AppState, key: str):
|
| 632 |
-
if s is not None and key:
|
| 633 |
-
key = str(key)
|
| 634 |
-
if key != s.model_repo_key:
|
| 635 |
-
# Update and drop current model to reload lazily next time
|
| 636 |
-
s.is_switching_model = True
|
| 637 |
-
s.model_repo_key = key
|
| 638 |
-
s.model_repo_id = None
|
| 639 |
-
s.model = None
|
| 640 |
-
s.processor = None
|
| 641 |
-
# Stream progress text while loading (first yield shows text)
|
| 642 |
-
yield gr.update(visible=True, value=f"Loading checkpoint: {key}...")
|
| 643 |
-
ensure_session_for_current_model(s)
|
| 644 |
-
if s is not None:
|
| 645 |
-
s.is_switching_model = False
|
| 646 |
-
# Final yield hides the text
|
| 647 |
-
yield gr.update(visible=False, value="")
|
| 648 |
-
|
| 649 |
-
ckpt_radio.change(_on_ckpt_change, inputs=[GLOBAL_STATE, ckpt_radio], outputs=[ckpt_progress])
|
| 650 |
-
|
| 651 |
def _sync_frame_idx(state_in: AppState, idx: int):
|
| 652 |
if state_in is not None:
|
| 653 |
state_in.current_frame_idx = int(idx)
|
|
|
|
| 122 |
self.pending_box_start_obj_id: int | None = None
|
| 123 |
self.is_switching_model: bool = False
|
| 124 |
# Model selection
|
| 125 |
+
self.model_repo_key: str = "EdgeTAM"
|
| 126 |
self.model_repo_id: str | None = None
|
| 127 |
self.session_repo_id: str | None = None
|
| 128 |
|
|
|
|
| 135 |
|
| 136 |
|
| 137 |
def _model_repo_from_key(key: str) -> str:
|
| 138 |
+
mapping = {"EdgeTAM": "yonigozlan/EdgeTAM-hf"}
|
| 139 |
+
return mapping.get(key)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
|
| 141 |
|
| 142 |
def load_model_if_needed(GLOBAL_STATE: gr.State) -> tuple[AutoModel, Sam2VideoProcessor, str, torch.dtype]:
|
|
|
|
| 527 |
|
| 528 |
theme = Soft(primary_hue="blue", secondary_hue="rose", neutral_hue="slate")
|
| 529 |
|
| 530 |
+
with gr.Blocks(title="EdgeTAM Video (Transformers) - Interactive Segmentation", theme=theme) as demo:
|
| 531 |
GLOBAL_STATE = gr.State(AppState())
|
| 532 |
|
| 533 |
gr.Markdown(
|
| 534 |
"""
|
| 535 |
+
### EdgeTAM Video Tracking · powered by Hugging Face 🤗 Transformers
|
| 536 |
+
Segment and track objects across a video with EdgeTAM. This demo runs the official implementation from the Hugging Face Transformers library for interactive, promptable video segmentation.
|
| 537 |
"""
|
| 538 |
)
|
| 539 |
with gr.Row():
|
|
|
|
| 542 |
"""
|
| 543 |
**Quick start**
|
| 544 |
- **Load a video**: Upload your own or pick an example below.
|
|
|
|
| 545 |
- **Points mode**: Select an Object ID and point label (positive/negative), then click the frame to add guidance. You can add **multiple points per object** and define **multiple objects** across frames.
|
| 546 |
- **Boxes mode**: Click two opposite corners to draw a box. Old inputs for that object are cleared automatically.
|
| 547 |
"""
|
|
|
|
| 553 |
- **Preview**: Use the slider to navigate frames and see the current masks.
|
| 554 |
- **Propagate**: Click “Propagate across video” to track all defined objects through the entire video. The preview follows progress periodically to keep things responsive.
|
| 555 |
- **Export**: Render an MP4 for smooth playback using the original video FPS.
|
| 556 |
+
- **Note**: More info on the Hugging Face 🤗 Transformers implementation of EdgeTAM can be found [here](https://huggingface.co/docs/transformers/en/main/en/model_doc/edgetam_video).
|
| 557 |
"""
|
| 558 |
)
|
| 559 |
|
| 560 |
with gr.Row():
|
| 561 |
with gr.Column(scale=1):
|
| 562 |
video_in = gr.Video(label="Upload video", sources=["upload", "webcam"], interactive=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 563 |
load_status = gr.Markdown(visible=True)
|
| 564 |
reset_btn = gr.Button("Reset Session", variant="secondary")
|
| 565 |
with gr.Column(scale=2):
|
|
|
|
| 615 |
render_btn = gr.Button("Render MP4 for smooth playback", variant="primary")
|
| 616 |
playback_video = gr.Video(label="Rendered Playback", interactive=False)
|
| 617 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 618 |
def _sync_frame_idx(state_in: AppState, idx: int):
|
| 619 |
if state_in is not None:
|
| 620 |
state_in.current_frame_idx = int(idx)
|