sparse4d记录

张开发
2026/4/11 5:40:13 15 分钟阅读

分享文章

sparse4d记录
instance bank介绍num_anchor:总anchor个数包括历史的num_cur:当前帧预测的query个数num_temp:历史保存的query个数num_anchor num_cur num_tempget:forward时在所有decoder layer推理前调用。if 有历史信息历史结果egopose变换到当前帧并更新self.cached_anchor . 类似prepare的作用, cached_anchor应该历史保存的num_temp个else if 没有历史信息resetupdate第一层refine后调用将当前帧预测的query取top num_cur 个和历史num_temp个拼接。返回拼接后的 num_anchor 个query,不更新self.cached_anchorcache:所有decoder layer结束后调用取topk个query保存下来,更新 self.cached_anchordef forward:query instancebanck.get()for i in range(num_decoder_layer):query decoder_layer(query) # 从当前帧预测出num_anchor个queryif i 0:query instancebank.update(query)isinstancebank.cache(query) # 保存num_temp个query到instancebank中[2:] 截断后去掉首个 gnn, norm[deformable, ffn, norm, refine,temp_gnn, gnn, norm, deformable, ffn, norm, refine, (×5)]完整调用流程图forward() 开始│├─ instance_bank.get()│ 返回:│ instance_feature [B, num_anchor, C] ← 可学习参数不含历史│ anchor [B, num_anchor, D]│ temp_instance_feature cached_feature ← 上帧缓存可能为 None│ temp_anchor cached_anchor│ time_interval│├─ 拼接 dn_anchor → anchor / instance_feature 变为 [B, num_anchornum_dn, *]││ ════════ 单帧 Decoder第0轮只有后半段 ════════│├─ [op: deformable] 图像特征采样更新 instance_feature├─ [op: ffn] 前馈网络├─ [op: norm] Layer Norm├─ [op: refine] 预测 anchor/cls/quality│ prediction[anchor_0], classification[cls_0]│ len(prediction)1 num_single_frame_decoder ← 触发│ ││ └─ instance_bank.update(instance_feature, anchor, cls)│ ┌─ 若 cached_feature 为 None第一帧→ 直接返回不变│ └─ 否则│ topk 选出当前帧 top-(num_anchor-num_temp) 个实例│ 拼接 [cached_feature(历史) | selected_feature(当前)]│ instance_feature 更新为 [历史|当前] 混合shape 仍 [B, num_anchor, C]││ ════════ 时序 Decoder ×5 ════════││ ┌─ [op: temp_gnn] ← 跨帧 cross-attention│ │ query instance_feature已含历史│ │ key/value temp_instance_feature纯历史 cached_feature│ │ → 融合时序信息更新 instance_feature│ ││ ├─ [op: gnn] 帧内 self-attention│ ├─ [op: norm]│ ├─ [op: deformable] 图像特征采样│ ├─ [op: ffn]│ ├─ [op: norm]│ └─ [op: refine] 预测 anchor/cls/quality追加到 prediction/classification│ ×5 重复│├─ instance_bank.cache(instance_feature, anchor, cls)│ topk 选 num_temp_instances 个高置信度实例│ 存入 cached_feature / cached_anchor ← 供下一帧 temp_gnn 使用│└─ [仅推理] instance_bank.get_instance_id(cls, anchor)分配/继承跨帧 instance ID用于追踪关键设计点总结┌───────────────────┬────────────────────────────────────────────────────────┐│ 阶段 │ instance_feature 内容 │├───────────────────┼────────────────────────────────────────────────────────┤│ get() 之后 │ 纯可学习参数无历史 │├───────────────────┼────────────────────────────────────────────────────────┤│ 单帧 decoder 期间 │ 当前帧图像特征驱动 │├───────────────────┼────────────────────────────────────────────────────────┤│ update() 之后 │ [:num_temp_instances] 历史[num_temp:] 当前 top-N │├───────────────────┼────────────────────────────────────────────────────────┤

更多文章