修复清空所有传播帧人工帧确认
- 清空所有传播帧时按传播链 seed 到传播结果的完整帧段检查人工/AI 标注帧 - 从传播结果帧触发清空时也会弹出是否删除人工/AI 标注帧确认 - 用户确认删除人工帧时同步删除该跨度内人工/AI 帧的全部遮罩 - 补充 VideoWorkspace 回归测试覆盖中间 AI 标注帧场景 - 更新项目指南和设计冻结文档
This commit is contained in:
@@ -267,7 +267,7 @@ uvicorn main:app --host 0.0.0.0 --port 8000 --reload
|
||||
- 右侧实例属性面板“边缘平滑强度/应用边缘平滑”已接入 `POST /api/ai/smooth-mask`;滑杆会即时更新数值,但后端预览请求有短防抖,避免拖动时连续请求卡顿;预览不写入撤销历史也不标 dirty;点击应用后会把返回 polygon 作为新的实际 mask 几何写入当前 mask 和同传播链前后对应 mask,整次应用作为一个撤销/重做历史步骤,相关 mask 标记为 dirty/draft,平滑强度重置为 0,用户可继续用 polygon 编辑工具调整新多边形。
|
||||
- 工作区“自动传播”按钮位于左侧工具栏橡皮擦下方,并已接入 `POST /api/ai/propagate/task`;若用户尚未显式设置范围,第一次点击会进入时间轴范围选择模式,顶栏才显示传播权重和向前/向后帧数,第二次点击“开始传播”才提交后台任务;当前启用所选 SAM 2.1 变体的视频 predictor 后台任务,运行中轮询任务进度,完成后刷新后端已保存标注;同一参考帧多个同类别 seed 会按来源 id 分开传播,不会因 label/color 相同互相覆盖;中空 seed 会把内洞传给后端,SAM 2 seed mask 栅格化时扣除内洞,传播结果保存时也会保留 `holes`;GPU/CPU 模型状态只在左侧 Sidebar 底部用紧凑徽标展示,工作区顶栏不再重复显示,具体 SAM 2.1 传播权重由顶栏下拉选择;同步 `POST /api/ai/propagate` 仍作为单 seed 兼容接口保留。
|
||||
- 工作区顶栏短状态会自动消失;保存、导出、导入 GT、传播进行中和无帧项目提示会保留到状态变化。
|
||||
- 工作区“清空遮罩”和左侧 `DEL` 删除只从左侧工具栏或键盘触发,会在删除已保存标注前预检当前项目仍存在的 annotation id,只对存在的 id 调用 `DELETE /api/ai/annotations/{id}`;如果当前帧有选中 mask 则优先清/删选中 mask,没有选中时清当前帧全部 mask;如果对象没关联其它传播帧则直接处理当前帧,如果存在传播链结果则弹窗在同一行选择取消、只处理当前帧、按帧范围选择或清空所有传播帧;按帧范围选择复用工作区时间轴范围选择和最终确认弹窗;按范围清空或清空所有传播帧时,如果目标帧范围内包含人工绘制或独立 AI 标注帧,会再提示是否删除人工/AI 标注帧,选择否时整帧保留,只清其它自动传播帧;工作区顶栏不再提供重复的“清空片段遮罩”。
|
||||
- 工作区“清空遮罩”和左侧 `DEL` 删除只从左侧工具栏或键盘触发,会在删除已保存标注前预检当前项目仍存在的 annotation id,只对存在的 id 调用 `DELETE /api/ai/annotations/{id}`;如果当前帧有选中 mask 则优先清/删选中 mask,没有选中时清当前帧全部 mask;如果对象没关联其它传播帧则直接处理当前帧,如果存在传播链结果则弹窗在同一行选择取消、只处理当前帧、按帧范围选择或清空所有传播帧;按帧范围选择复用工作区时间轴范围选择和最终确认弹窗;按范围清空或清空所有传播帧时,如果目标帧范围内包含人工绘制或独立 AI 标注帧,会再提示是否删除人工/AI 标注帧;清空所有传播帧会按传播链 seed 与传播结果跨越的完整帧段检查人工/AI 帧,不只检查实际要删除的自动传播 mask 所在帧;选择否时整帧保留,只清其它自动传播帧;工作区顶栏不再提供重复的“清空片段遮罩”。
|
||||
- 项目状态已统一为 `pending`、`parsing`、`ready`、`error`;前端 `src/lib/api.ts` 会兼容归一化旧库中可能存在的 `Ready`、`Parsing`、`Error`。
|
||||
- 项目库的视频导入与生成帧是两个独立动作:导入视频只上传源文件,并通过 Axios `onUploadProgress` 在项目库显示导入进度;生成帧按钮才会带 `parse_fps` 调用 `/api/media/parse`;DICOM 批量导入也会显示上传进度和文件数量,上传完成后创建解析任务并轮询显示解析进度。工作区不会再因“有视频但无帧”自动创建拆帧任务。
|
||||
- `server.ts` 不再提供旧版 `/api/login`、`/api/projects`、`/api/templates` mock;当前前端真实 API 调用走 FastAPI 的 `/api/auth/*`、`/api/projects`、`/api/templates` 等接口。
|
||||
|
||||
@@ -158,7 +158,7 @@
|
||||
21. 新 mask 会带上当前选择的模板分类元数据,包括 `classId`、`className`、`classZIndex`、`metadata.source=ai_segmentation` 和保存状态 `draft`。
|
||||
20. 顶栏保存状态按钮按当前项目待保存数量显示为“保存 X 个改动”或“已全部保存”;用户点击保存后,前端将像素 `segmentation` 转成 normalized `mask_data.polygons`;未保存 mask 调用 `POST /api/ai/annotate`,dirty mask 会先读取当前后端标注 id 列表,已知存在的 id 调用 `PATCH /api/ai/annotations/{annotation_id}`,已知缺失的本地旧 id 直接保留同一 `mask_data`、几何、分类和传播 lineage metadata 改用 `POST /api/ai/annotate` 重新创建;如果预检后发生并发删除导致 `PATCH` 返回 404,也会降级为重新创建,并在随后回显时排除本地旧 mask id;保存成功后本次提交的 draft mask id 会从本地保留列表中排除,并由后端 saved annotation 回显替换。
|
||||
21. 工作区加载项目帧后通过 `GET /api/ai/annotations` 取回已保存标注并转成前端 mask。
|
||||
22. 工作区“清空遮罩”只从左侧工具栏触发;如果当前帧存在选中 mask,则以当前帧选中 mask 为清空对象,否则以当前帧全部 mask 为清空对象。如果清空对象没有关联其它传播帧,直接删除当前帧已保存标注并清除当前帧本地 mask,不弹确认;如果存在传播链结果,`VideoWorkspace` 弹出范围选择,用户可在同一行选择取消、只清当前帧、按帧范围选择或清空当前帧及同传播链所有自动传播帧;按帧范围选择复用时间轴范围选择并在顶栏“确认清空”后最终确认。按范围清空或清空所有传播帧时,如果目标帧范围包含人工/AI 标注帧,会二次询问是否删除;选择是会删除这些人工/AI 标注帧中的全部 mask,选择否时这些帧整帧保留,只清其它自动传播帧。本操作不删除其它帧独立 AI 推理或人工 mask。左侧工具栏的 `DEL` 按钮和键盘 Delete/Backspace 删除整块 mask 时复用同一传播链范围确认;删除已保存标注前会通过 `GET /api/ai/annotations` 预检当前项目仍存在的 annotation id,只对存在的 id 发送 `DELETE`。
|
||||
22. 工作区“清空遮罩”只从左侧工具栏触发;如果当前帧存在选中 mask,则以当前帧选中 mask 为清空对象,否则以当前帧全部 mask 为清空对象。如果清空对象没有关联其它传播帧,直接删除当前帧已保存标注并清除当前帧本地 mask,不弹确认;如果存在传播链结果,`VideoWorkspace` 弹出范围选择,用户可在同一行选择取消、只清当前帧、按帧范围选择或清空当前帧及同传播链所有自动传播帧;按帧范围选择复用时间轴范围选择并在顶栏“确认清空”后最终确认。按范围清空或清空所有传播帧时,如果目标帧范围包含人工/AI 标注帧,会二次询问是否删除;其中清空所有传播帧会用传播链 seed 与传播结果跨越的完整帧段检查人工/AI 帧,避免从传播结果帧触发时漏掉中间独立 AI/人工帧;选择是会删除这些人工/AI 标注帧中的全部 mask,选择否时这些帧整帧保留,只清其它自动传播帧。本操作不删除其它帧独立 AI 推理或人工 mask。左侧工具栏的 `DEL` 按钮和键盘 Delete/Backspace 删除整块 mask 时复用同一传播链范围确认;删除已保存标注前会通过 `GET /api/ai/annotations` 预检当前项目仍存在的 annotation id,只对存在的 id 发送 `DELETE`。
|
||||
|
||||
### 视频片段传播
|
||||
|
||||
|
||||
@@ -735,6 +735,73 @@ describe('VideoWorkspace', () => {
|
||||
expect(useStore.getState().masks.map((mask) => mask.id).sort()).toEqual(['annotation-1']);
|
||||
});
|
||||
|
||||
it('asks about AI-only frames across the propagation span when clearing all propagated masks', async () => {
|
||||
apiMock.getProjectFrames.mockResolvedValueOnce([
|
||||
{ id: 10, project_id: 1, frame_index: 0, image_url: '/frame-0.jpg', width: 640, height: 360 },
|
||||
{ id: 11, project_id: 1, frame_index: 1, image_url: '/frame-1.jpg', width: 640, height: 360 },
|
||||
{ id: 12, project_id: 1, frame_index: 2, image_url: '/frame-2.jpg', width: 640, height: 360 },
|
||||
{ id: 13, project_id: 1, frame_index: 3, image_url: '/frame-3.jpg', width: 640, height: 360 },
|
||||
]);
|
||||
apiMock.deleteAnnotation.mockResolvedValue(undefined);
|
||||
|
||||
render(<VideoWorkspace />);
|
||||
await waitFor(() => expect(useStore.getState().frames).toHaveLength(4));
|
||||
act(() => {
|
||||
useStore.setState({
|
||||
currentFrameIndex: 3,
|
||||
masks: [
|
||||
{ id: 'annotation-1', annotationId: '1', frameId: '10', pathData: 'M 0 0 Z', label: 'Seed', color: '#06b6d4', saved: true, saveStatus: 'saved' },
|
||||
{
|
||||
id: 'annotation-11',
|
||||
annotationId: '11',
|
||||
frameId: '11',
|
||||
pathData: 'M 4 4 Z',
|
||||
label: 'AI edit',
|
||||
color: '#f97316',
|
||||
saved: true,
|
||||
saveStatus: 'saved',
|
||||
metadata: { source: 'ai_segmentation' },
|
||||
},
|
||||
{
|
||||
id: 'annotation-20',
|
||||
annotationId: '20',
|
||||
frameId: '12',
|
||||
pathData: 'M 2 2 Z',
|
||||
label: 'Propagated',
|
||||
color: '#06b6d4',
|
||||
saved: true,
|
||||
saveStatus: 'saved',
|
||||
metadata: { source: 'sam2_propagation', source_annotation_id: 1, source_mask_id: 'annotation-1', propagation_seed_key: 'annotation:1' },
|
||||
},
|
||||
{
|
||||
id: 'annotation-30',
|
||||
annotationId: '30',
|
||||
frameId: '13',
|
||||
pathData: 'M 3 3 Z',
|
||||
label: 'Propagated',
|
||||
color: '#06b6d4',
|
||||
saved: true,
|
||||
saveStatus: 'saved',
|
||||
metadata: { source: 'sam2_propagation', source_annotation_id: 1, source_mask_id: 'annotation-1', propagation_seed_key: 'annotation:1' },
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
fireEvent.click(screen.getByTitle('清空遮罩'));
|
||||
fireEvent.click(screen.getByRole('button', { name: '清空所有传播帧' }));
|
||||
|
||||
expect(screen.getByText('是否删除人工/AI 标注帧')).toBeInTheDocument();
|
||||
expect(screen.getByText(/第 1、2 帧/)).toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole('button', { name: '是,删除人工帧' }));
|
||||
|
||||
await waitFor(() => expect(apiMock.deleteAnnotation).toHaveBeenCalledWith('30'));
|
||||
expect(apiMock.deleteAnnotation).toHaveBeenCalledWith('20');
|
||||
expect(apiMock.deleteAnnotation).toHaveBeenCalledWith('1');
|
||||
expect(apiMock.deleteAnnotation).toHaveBeenCalledWith('11');
|
||||
expect(useStore.getState().masks).toEqual([]);
|
||||
});
|
||||
|
||||
it('can clear only the current frame when current masks have propagated results', async () => {
|
||||
apiMock.getProjectFrames.mockResolvedValueOnce([
|
||||
{ id: 10, project_id: 1, frame_index: 0, image_url: '/frame.jpg', width: 640, height: 360 },
|
||||
|
||||
@@ -1010,6 +1010,25 @@ export function VideoWorkspace({ onNavigateToAI }: { onNavigateToAI?: () => void
|
||||
});
|
||||
}, [executeClearCurrentMasks, frameNumberById, resetClearPropagationRangeSelection]);
|
||||
|
||||
const propagationSpanFrameIdsForClearRequest = useCallback((request: CurrentClearConfirmState): string[] | undefined => {
|
||||
const latestMasks = useStore.getState().masks;
|
||||
const spanMaskIds = new Set([
|
||||
...request.currentMaskIds,
|
||||
...request.propagatedMaskIds,
|
||||
...Array.from(findPropagationChainMaskIds(request.currentMaskIds, latestMasks)),
|
||||
]);
|
||||
const spanFrameNumbers = latestMasks
|
||||
.filter((mask) => spanMaskIds.has(mask.id))
|
||||
.map((mask) => frameNumberById.get(String(mask.frameId)))
|
||||
.filter((frameNumber): frameNumber is number => Boolean(frameNumber));
|
||||
|
||||
if (spanFrameNumbers.length === 0) return undefined;
|
||||
const startIndex = Math.max(0, Math.min(...spanFrameNumbers) - 1);
|
||||
const endIndex = Math.min(frames.length - 1, Math.max(...spanFrameNumbers) - 1);
|
||||
if (endIndex < startIndex) return undefined;
|
||||
return frames.slice(startIndex, endIndex + 1).map((frame) => String(frame.id));
|
||||
}, [frameNumberById, frames]);
|
||||
|
||||
const handleResolveClearManualFrameConfirm = useCallback(async (includeManualFrames: boolean) => {
|
||||
if (!pendingClearManualFrameConfirm) return;
|
||||
const targetMaskIds = includeManualFrames
|
||||
@@ -2285,7 +2304,11 @@ export function VideoWorkspace({ onNavigateToAI }: { onNavigateToAI?: () => void
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => requestClearMasksWithManualFrameConfirm(pendingCurrentClearConfirm.propagatedMaskIds, '当前帧及传播链')}
|
||||
onClick={() => requestClearMasksWithManualFrameConfirm(
|
||||
pendingCurrentClearConfirm.propagatedMaskIds,
|
||||
'当前帧及传播链',
|
||||
{ manualFrameScopeIds: propagationSpanFrameIdsForClearRequest(pendingCurrentClearConfirm) },
|
||||
)}
|
||||
className="rounded bg-red-500 px-2 py-2 text-xs font-semibold text-white hover:bg-red-400 disabled:opacity-60"
|
||||
disabled={isSaving}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user