John Ho Claude Opus 4.8 (1M context) commited on
Commit ·
abcd56e
1
Parent(s): d23051a
Fix multi-object video inference crash by seeding all masks in one call
Browse filesrun_sam_video_inference added input masks one-per-call in a loop, but
add_inputs_to_inference_session overwrites session.obj_with_new_inputs on
every call rather than accumulating. This left only the last object marked
as "new", so during the seed forward pass every earlier object was treated
as a non-initial-conditioning frame and raised:
ValueError: maskmem_features in conditioning outputs cannot be empty
when not is_initial_conditioning_frame
Any request with 2+ masks hit this regardless of ref_frame_idx. Seed all
objects in a single add_inputs_to_inference_session call so every object is
registered before propagation; keep the per-mask debug logging in its own
loop.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- samv2_handler.py +12 -10
samv2_handler.py
CHANGED
|
@@ -127,9 +127,7 @@ def run_sam_im_inference(
|
|
| 127 |
outputs.pred_masks.cpu(), inputs["original_sizes"]
|
| 128 |
)[0]
|
| 129 |
|
| 130 |
-
output_masks = [
|
| 131 |
-
np.asarray(mask).squeeze().astype(np.uint8) for mask in masks
|
| 132 |
-
]
|
| 133 |
return (
|
| 134 |
[b64_mask_encode(m).decode("ascii") for m in output_masks]
|
| 135 |
if b64_encode_mask
|
|
@@ -226,15 +224,19 @@ def run_sam_video_inference(
|
|
| 226 |
frames = [Image.open(fp).convert("RGB") for fp in frame_paths]
|
| 227 |
|
| 228 |
session = processor.init_video_session(video=frames, inference_device=device)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
for mask_idx, mask in enumerate(masks):
|
| 230 |
-
processor.add_inputs_to_inference_session(
|
| 231 |
-
inference_session=session,
|
| 232 |
-
frame_idx=ref_frame_idx,
|
| 233 |
-
obj_ids=mask_idx,
|
| 234 |
-
input_masks=mask,
|
| 235 |
-
)
|
| 236 |
logger.debug(
|
| 237 |
-
f"
|
| 238 |
)
|
| 239 |
|
| 240 |
# seed the reference frame
|
|
|
|
| 127 |
outputs.pred_masks.cpu(), inputs["original_sizes"]
|
| 128 |
)[0]
|
| 129 |
|
| 130 |
+
output_masks = [np.asarray(mask).squeeze().astype(np.uint8) for mask in masks]
|
|
|
|
|
|
|
| 131 |
return (
|
| 132 |
[b64_mask_encode(m).decode("ascii") for m in output_masks]
|
| 133 |
if b64_encode_mask
|
|
|
|
| 224 |
frames = [Image.open(fp).convert("RGB") for fp in frame_paths]
|
| 225 |
|
| 226 |
session = processor.init_video_session(video=frames, inference_device=device)
|
| 227 |
+
# Seed all objects in a single call. add_inputs_to_inference_session overwrites
|
| 228 |
+
# session.obj_with_new_inputs on every call, so adding masks one-per-call would leave
|
| 229 |
+
# only the last object registered as "new" -- the earlier objects would then be treated
|
| 230 |
+
# as non-initial-conditioning frames and crash gathering memory that doesn't exist yet.
|
| 231 |
+
processor.add_inputs_to_inference_session(
|
| 232 |
+
inference_session=session,
|
| 233 |
+
frame_idx=ref_frame_idx,
|
| 234 |
+
obj_ids=list(range(len(masks))),
|
| 235 |
+
input_masks=[m for m in masks],
|
| 236 |
+
)
|
| 237 |
for mask_idx, mask in enumerate(masks):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
logger.debug(
|
| 239 |
+
f"added mask {mask_idx} of shape {mask.shape} for frame {ref_frame_idx}, xyxy: {mask_to_xyxy(mask)}"
|
| 240 |
)
|
| 241 |
|
| 242 |
# seed the reference frame
|