facebookresearch / sam2

The repository provides code for running inference with the Meta Segment Anything Model 2 (SAM 2), links for downloading the trained model checkpoints, and example notebooks that show how to use the model.
Apache License 2.0
12.73k stars 1.19k forks source link

When my ann_frame_idx is not 0, running the model throws an error #418

Open gxwawgw opened 1 month ago

gxwawgw commented 1 month ago

ann_frame_idx = 24 # the frame index we interact with

When my ann_frame_idx is not 0, running the model throws an error: "for out_obj_id, out_mask in video_segments[out_frame_idx].items(): KeyError: 0". This indicates that when I execute predictor.propagate_in_video(inference_state), the model only propagates backward. How can I make the model propagate across all images?

hariharan1412 commented 1 month ago
vis_frame_stride = 30
plt.close("all")
for out_frame_idx in range(0, len(frame_names), vis_frame_stride):
    plt.figure(figsize=(6, 4))
    plt.title(f"frame {out_frame_idx}")
    plt.imshow(Image.open(os.path.join(video_dir, frame_names[out_frame_idx])))
    for out_obj_id, out_mask in video_segments[out_frame_idx].items():
        show_mask(out_mask, plt.gca(), obj_id=out_obj_id)    

I'm assuming you are using this code, If its true Adjust the Range() function in for loop