golf_tracking / test.py
rehctiw25's picture
Upload folder using huggingface_hub
013216e verified
raw
history blame contribute delete
711 Bytes
# ```python
# import torch
# from sam2.build_sam import build_sam2_video_predictor
# checkpoint = "./checkpoints/sam2.1_hiera_large.pt"
# model_cfg = "configs/sam2.1/sam2.1_hiera_l.yaml"
# predictor = build_sam2_video_predictor(model_cfg, checkpoint)
# with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16):
# state = predictor.init_state(<your_video>)
# # add new prompts and instantly get the output on the same frame
# frame_idx, object_ids, masks = predictor.add_new_points_or_box(state, <your_prompts>):
# # propagate the prompts to get masklets throughout the video
# for frame_idx, object_ids, masks in predictor.propagate_in_video(state):
# ...
# ```