(
config_file,
ckpt_path=None,
device="cuda",
mode="eval",
hydra_overrides_extra=[],
apply_postprocessing=True,
**kwargs,
)
| 69 | |
| 70 | |
| 71 | def 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 | |
| 100 | def build_sam2_video_predictor( |
no test coverage detected