BiliSakura commited on
Commit
58d2f2f
·
verified ·
1 Parent(s): d5a29fb

Update all files for SegEarth-OV

Browse files
Files changed (1) hide show
  1. OV-2/pipeline.py +38 -0
OV-2/pipeline.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ SegEarth OV-2 pipeline. Self-contained; uses config.json and weights/featup/ in this folder.
3
+ """
4
+ import json
5
+ from pathlib import Path
6
+
7
+ import sys
8
+ _parent = Path(__file__).resolve().parent.parent
9
+ if str(_parent) not in sys.path:
10
+ sys.path.insert(0, str(_parent))
11
+ from pipeline import SegEarthPipelineCLIP
12
+
13
+
14
+ def load(config_path: Path = None, model_id: str = None, **kwargs):
15
+ """Load OV-2 pipeline with config from this folder."""
16
+ repo_dir = Path(__file__).parent
17
+ cfg_path = config_path or repo_dir / "config.json"
18
+ with open(cfg_path) as f:
19
+ cfg = json.load(f)
20
+ local_backbone = cfg.get("local_backbone")
21
+ if local_backbone:
22
+ local_path = repo_dir / local_backbone
23
+ if local_path.exists():
24
+ kwargs.setdefault("model_id", str(local_path))
25
+ if "model_id" not in kwargs:
26
+ kwargs.setdefault("model_id", model_id or cfg["model_id"])
27
+ kwargs.setdefault("featup_model", cfg.get("featup") or "jbu_one")
28
+ kwargs.setdefault("cls_token_lambda", cfg.get("cls_token_lambda", -0.3))
29
+ kwargs.setdefault("logit_scale", cfg.get("logit_scale", 50.0))
30
+ featup_name = (cfg.get("featup_weights") or "xclip_jbu_one_million_aid.ckpt").split("/")[-1]
31
+ local_featup = repo_dir / "weights" / "featup" / featup_name
32
+ if local_featup.exists():
33
+ kwargs.setdefault("featup_weights_path", local_featup)
34
+ kwargs.setdefault("class_names_path", repo_dir / "configs" / "cls_openearthmap_sar.txt")
35
+ return SegEarthPipelineCLIP(**kwargs)
36
+
37
+
38
+ SegEarthPipeline = load