Buckets:
| """Abstract interface for video segmentation backends.""" | |
| from __future__ import annotations | |
| from abc import ABC, abstractmethod | |
| from collections.abc import Iterator | |
| import numpy as np | |
| from fpgm.types import FrameMasks | |
| class VideoSegmenter(ABC): | |
| """Stateful promptable video segmentation. | |
| Lifecycle: :meth:`start_session` -> :meth:`add_text_prompt` / | |
| :meth:`add_point_prompt` -> :meth:`propagate` -> :meth:`close_session`. | |
| Implementations must be usable as a context manager so sessions are always | |
| released, which matters on a shared GPU. | |
| """ | |
| def start_session(self, video_path: str) -> str: | |
| """Open a session on a JPEG folder or mp4; returns a session id.""" | |
| def add_text_prompt(self, frame_idx: int, text: str) -> FrameMasks: | |
| """Prompt with a natural-language phrase; returns that frame's masks.""" | |
| def add_point_prompt( | |
| self, | |
| frame_idx: int, | |
| points_xy: np.ndarray, | |
| labels: np.ndarray, | |
| obj_id: int | None = None, | |
| ) -> FrameMasks: | |
| """Prompt with positive/negative clicks in absolute pixel coordinates.""" | |
| def propagate(self) -> Iterator[FrameMasks]: | |
| """Stream per-frame masks across the whole video.""" | |
| def reset_session(self) -> None: | |
| """Clear prompts. Required before switching to a different text prompt.""" | |
| def close_session(self) -> None: | |
| """Release the session and its GPU memory.""" | |
| def __enter__(self) -> "VideoSegmenter": | |
| return self | |
| def __exit__(self, *exc_info: object) -> None: | |
| self.close_session() | |
Xet Storage Details
- Size:
- 1.71 kB
- Xet hash:
- 65b44d72381f7c109e9a3f984cd4d3ed6a47dd82877f3bfcac84953c832ed4c4
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.