- 接入 SAM2 视频传播能力:新增 /api/ai/propagate,支持用当前帧 mask/polygon/bbox 作为 seed,通过 SAM2 video predictor 向前、向后或双向传播,并可保存为真实 annotation。 - 接入 SAM3 video tracker:通过独立 Python 3.12 external worker 调用 SAM3 video predictor/tracker,使用本地 checkpoint 与 bbox seed 执行视频级跟踪,并在模型状态中标记 video_track 能力。 - 完善 SAM 模型分发:sam_registry 按 model_id 明确区分 sam2 propagation 与 sam3 video_track,避免两个模型链路混用。 - 打通前端“传播片段”:VideoWorkspace 使用当前选中 mask 和当前 AI 模型调用后端传播接口,传播结果回写并刷新工作区已保存标注。 - 增强 SAM3 本地 checkpoint 配置:新增 sam3_checkpoint_path 配置和 .env.example 示例,状态检查改为基于本地 checkpoint/独立环境/模型包可用性。 - 完善视频拆帧参数:/api/media/parse 支持 parse_fps、max_frames、target_width,后端任务保存帧时间戳、源帧号和 frame_sequence 元数据。 - 增加运行时 schema 兼容处理:启动时为旧 frames 表补充 timestamp_ms 和 source_frame_number 列,避免旧库升级后缺字段。 - 强化 Canvas 标注编辑:补齐多边形闭合、点工具、顶点拖拽、边中点插入、Delete/Backspace 删除、区域合并和重叠去除等交互。 - 增强语义分类联动:选中 mask 后可通过右侧语义分类树更新标签、颜色和 class metadata,并同步到保存/导出链路。 - 增加关键帧时间轴体验:FrameTimeline 显示具体时间信息,并支持键盘左右方向键切换关键帧。 - 完善 AI 交互分割参数:前端保留正向点、反向点、框选和 interactive prompt 的调用状态,支持 SAM2 细化候选区域与 SAM3 bbox 入口。 - 扩展后端/前端 API 类型:新增 propagateMasks、传播请求/响应 schema,并补齐 annotation、导出、模型状态和任务接口的测试覆盖。 - 更新项目文档:同步 README、AGENTS、接口契约、需求冻结、设计冻结、前端元素审计、实施计划和测试计划,标明真实功能边界与剩余风险。 - 增加测试覆盖:补充 SAM2/SAM3 传播、SAM3 状态、媒体拆帧参数、Canvas 编辑、语义标签切换、时间轴、工作区传播和 API 合约测试。 - 加强仓库安全边界:将 sam3权重/ 加入 .gitignore,避免本地模型权重被误提交。 验证:npm run test:run;pytest backend/tests;npm run lint;npm run build;python -m py_compile;git diff --check。
157 lines
5.5 KiB
Python
157 lines
5.5 KiB
Python
"""SQLAlchemy ORM models."""
|
|
|
|
from sqlalchemy import (
|
|
Column,
|
|
Integer,
|
|
String,
|
|
Text,
|
|
DateTime,
|
|
ForeignKey,
|
|
JSON,
|
|
Float,
|
|
)
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.sql import func
|
|
|
|
from database import Base
|
|
from statuses import PROJECT_STATUS_PENDING
|
|
|
|
|
|
class Project(Base):
|
|
"""Project model representing a segmentation project."""
|
|
|
|
__tablename__ = "projects"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
name = Column(String(255), nullable=False)
|
|
description = Column(Text, nullable=True)
|
|
video_path = Column(String(512), nullable=True)
|
|
thumbnail_url = Column(String(512), nullable=True)
|
|
status = Column(String(50), default=PROJECT_STATUS_PENDING, nullable=False)
|
|
source_type = Column(String(20), default="video", nullable=False) # video | dicom
|
|
original_fps = Column(Float, nullable=True)
|
|
parse_fps = Column(Float, default=30.0, nullable=False)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
updated_at = Column(
|
|
DateTime(timezone=True), server_default=func.now(), onupdate=func.now()
|
|
)
|
|
|
|
frames = relationship("Frame", back_populates="project", cascade="all, delete-orphan")
|
|
annotations = relationship(
|
|
"Annotation", back_populates="project", cascade="all, delete-orphan"
|
|
)
|
|
tasks = relationship(
|
|
"ProcessingTask", back_populates="project", cascade="all, delete-orphan"
|
|
)
|
|
|
|
|
|
class Frame(Base):
|
|
"""Frame model representing an extracted video frame."""
|
|
|
|
__tablename__ = "frames"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
project_id = Column(Integer, ForeignKey("projects.id", ondelete="CASCADE"), nullable=False)
|
|
frame_index = Column(Integer, nullable=False)
|
|
image_url = Column(String(512), nullable=False)
|
|
width = Column(Integer, nullable=True)
|
|
height = Column(Integer, nullable=True)
|
|
timestamp_ms = Column(Float, nullable=True)
|
|
source_frame_number = Column(Integer, nullable=True)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
project = relationship("Project", back_populates="frames")
|
|
annotations = relationship(
|
|
"Annotation", back_populates="frame", cascade="all, delete-orphan"
|
|
)
|
|
|
|
|
|
class Template(Base):
|
|
"""Template (Ontology) model for segmentation classes."""
|
|
|
|
__tablename__ = "templates"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
name = Column(String(255), nullable=False)
|
|
description = Column(Text, nullable=True)
|
|
color = Column(String(50), nullable=False)
|
|
z_index = Column(Integer, default=0, nullable=False)
|
|
mapping_rules = Column(JSON, nullable=True)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
annotations = relationship(
|
|
"Annotation", back_populates="template", cascade="all, delete-orphan"
|
|
)
|
|
|
|
|
|
class Annotation(Base):
|
|
"""Annotation model for segmentation masks and prompts."""
|
|
|
|
__tablename__ = "annotations"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
project_id = Column(
|
|
Integer, ForeignKey("projects.id", ondelete="CASCADE"), nullable=False
|
|
)
|
|
frame_id = Column(
|
|
Integer, ForeignKey("frames.id", ondelete="CASCADE"), nullable=True
|
|
)
|
|
template_id = Column(
|
|
Integer, ForeignKey("templates.id", ondelete="SET NULL"), nullable=True
|
|
)
|
|
mask_data = Column(JSON, nullable=True)
|
|
points = Column(JSON, nullable=True)
|
|
bbox = Column(JSON, nullable=True)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
updated_at = Column(
|
|
DateTime(timezone=True), server_default=func.now(), onupdate=func.now()
|
|
)
|
|
|
|
project = relationship("Project", back_populates="annotations")
|
|
frame = relationship("Frame", back_populates="annotations")
|
|
template = relationship("Template", back_populates="annotations")
|
|
masks = relationship("Mask", back_populates="annotation", cascade="all, delete-orphan")
|
|
|
|
|
|
class Mask(Base):
|
|
"""Mask model for exported/derived mask files."""
|
|
|
|
__tablename__ = "masks"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
annotation_id = Column(
|
|
Integer, ForeignKey("annotations.id", ondelete="CASCADE"), nullable=False
|
|
)
|
|
mask_url = Column(String(512), nullable=False)
|
|
format = Column(String(50), default="png", nullable=False) # png / rle / json
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
annotation = relationship("Annotation", back_populates="masks")
|
|
|
|
|
|
class ProcessingTask(Base):
|
|
"""Background task state persisted for dashboard and polling."""
|
|
|
|
__tablename__ = "processing_tasks"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
task_type = Column(String(80), nullable=False)
|
|
status = Column(String(40), default="queued", nullable=False)
|
|
progress = Column(Integer, default=0, nullable=False)
|
|
message = Column(Text, nullable=True)
|
|
project_id = Column(
|
|
Integer, ForeignKey("projects.id", ondelete="CASCADE"), nullable=True
|
|
)
|
|
celery_task_id = Column(String(255), nullable=True)
|
|
payload = Column(JSON, nullable=True)
|
|
result = Column(JSON, nullable=True)
|
|
error = Column(Text, nullable=True)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
started_at = Column(DateTime(timezone=True), nullable=True)
|
|
finished_at = Column(DateTime(timezone=True), nullable=True)
|
|
updated_at = Column(
|
|
DateTime(timezone=True), server_default=func.now(), onupdate=func.now()
|
|
)
|
|
|
|
project = relationship("Project", back_populates="tasks")
|