MCPcopy
hub / github.com/yangchris11/samurai / build_sam2

Function build_sam2

sam2/sam2/build_sam.py:71–97  ·  view source on GitHub ↗
(
    config_file,
    ckpt_path=None,
    device="cuda",
    mode="eval",
    hydra_overrides_extra=[],
    apply_postprocessing=True,
    **kwargs,
)

Source from the content-addressed store, hash-verified

69
70
71def build_sam2(
72 config_file,
73 ckpt_path=None,
74 device="cuda",
75 mode="eval",
76 hydra_overrides_extra=[],
77 apply_postprocessing=True,
78 **kwargs,
79):
80
81 if apply_postprocessing:
82 hydra_overrides_extra = hydra_overrides_extra.copy()
83 hydra_overrides_extra += [
84 # dynamically fall back to multi-mask if the single mask is not stable
85 "++model.sam_mask_decoder_extra_args.dynamic_multimask_via_stability=true",
86 "++model.sam_mask_decoder_extra_args.dynamic_multimask_stability_delta=0.05",
87 "++model.sam_mask_decoder_extra_args.dynamic_multimask_stability_thresh=0.98",
88 ]
89 # Read config and init model
90 cfg = compose(config_name=config_file, overrides=hydra_overrides_extra)
91 OmegaConf.resolve(cfg)
92 model = instantiate(cfg.model, _recursive_=True)
93 _load_checkpoint(model, ckpt_path)
94 model = model.to(device)
95 if mode == "eval":
96 model.eval()
97 return model
98
99
100def build_sam2_video_predictor(

Callers 1

build_sam2_hfFunction · 0.85

Calls 4

_load_checkpointFunction · 0.85
evalMethod · 0.80
copyMethod · 0.45
toMethod · 0.45

Tested by

no test coverage detected