BiliSakura commited on
Commit
001049a
·
verified ·
1 Parent(s): eb4ceca

Update all files for SegEarth-OV

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