| """ |
| SegEarth OV pipeline. Self-contained; uses config.json and weights/featup/ in this folder. |
| """ |
| import json |
| from pathlib import Path |
|
|
| |
| import sys |
| _parent = Path(__file__).resolve().parent.parent |
| if str(_parent) not in sys.path: |
| sys.path.insert(0, str(_parent)) |
| from pipeline import SegEarthPipelineCLIP |
|
|
|
|
| def load(config_path: Path = None, model_id: str = None, **kwargs): |
| """Load OV pipeline with config from this folder.""" |
| repo_dir = Path(__file__).parent |
| cfg_path = config_path or repo_dir / "config.json" |
| with open(cfg_path) as f: |
| cfg = json.load(f) |
| local_backbone = cfg.get("local_backbone") |
| if local_backbone: |
| local_path = repo_dir / local_backbone |
| if local_path.exists(): |
| kwargs.setdefault("model_id", str(local_path)) |
| if "model_id" not in kwargs: |
| kwargs.setdefault("model_id", model_id or cfg["model_id"]) |
| kwargs.setdefault("featup_model", cfg.get("featup") or "jbu_one") |
| kwargs.setdefault("cls_token_lambda", cfg.get("cls_token_lambda", -0.3)) |
| kwargs.setdefault("logit_scale", cfg.get("logit_scale", 50.0)) |
| |
| featup_name = (cfg.get("featup_weights") or "xclip_jbu_one_million_aid.ckpt").split("/")[-1] |
| local_featup = repo_dir / "weights" / "featup" / featup_name |
| if local_featup.exists(): |
| kwargs.setdefault("featup_weights_path", local_featup) |
| kwargs.setdefault("class_names_path", repo_dir / "configs" / "cls_openearthmap_sar.txt") |
| return SegEarthPipelineCLIP(**kwargs) |
|
|
|
|
| SegEarthPipeline = load |
|
|