feat: regenerate paths in catalog and cache
Browse files- data/cache.tar.gz +2 -2
- data/catalog.tar.gz +1 -1
- scripts/precompute_cache.py +20 -1
- src/snowleopard_reid/cache.py +7 -1
data/cache.tar.gz
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6ab39ded3902bc775ffa102dafdd566ae066084318b28504651333268a8d0157
|
| 3 |
+
size 213436978
|
data/catalog.tar.gz
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 276174890
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7f50a73310600440e9ab53c081a12f637b33289815171ea80d6c9ebd28000c07
|
| 3 |
size 276174890
|
scripts/precompute_cache.py
CHANGED
|
@@ -81,6 +81,23 @@ TOP_K_DEFAULT = 5
|
|
| 81 |
ALL_EXTRACTORS = ["sift", "superpoint", "disk", "aliked"]
|
| 82 |
|
| 83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
def ensure_sam_model() -> Path:
|
| 85 |
"""Download SAM HQ model if not present.
|
| 86 |
|
|
@@ -269,7 +286,7 @@ def process_and_cache(
|
|
| 269 |
logger.info(f" Found {len(matches)} matches")
|
| 270 |
|
| 271 |
# ================================================================
|
| 272 |
-
# Enrich matches with location/body_part
|
| 273 |
# ================================================================
|
| 274 |
logger.info(" Adding location/body_part metadata...")
|
| 275 |
for match in matches:
|
|
@@ -278,6 +295,8 @@ def process_and_cache(
|
|
| 278 |
)
|
| 279 |
match["location"] = location
|
| 280 |
match["body_part"] = body_part
|
|
|
|
|
|
|
| 281 |
|
| 282 |
# ================================================================
|
| 283 |
# Set up cache directory
|
|
|
|
| 81 |
ALL_EXTRACTORS = ["sift", "superpoint", "disk", "aliked"]
|
| 82 |
|
| 83 |
|
| 84 |
+
def make_relative_path(filepath: str, project_root: Path) -> str:
|
| 85 |
+
"""Convert absolute path to relative path from project root.
|
| 86 |
+
|
| 87 |
+
Args:
|
| 88 |
+
filepath: Absolute or relative file path
|
| 89 |
+
project_root: Project root directory
|
| 90 |
+
|
| 91 |
+
Returns:
|
| 92 |
+
Relative path string from project root
|
| 93 |
+
"""
|
| 94 |
+
try:
|
| 95 |
+
return str(Path(filepath).relative_to(project_root))
|
| 96 |
+
except ValueError:
|
| 97 |
+
# Already relative or different root
|
| 98 |
+
return filepath
|
| 99 |
+
|
| 100 |
+
|
| 101 |
def ensure_sam_model() -> Path:
|
| 102 |
"""Download SAM HQ model if not present.
|
| 103 |
|
|
|
|
| 286 |
logger.info(f" Found {len(matches)} matches")
|
| 287 |
|
| 288 |
# ================================================================
|
| 289 |
+
# Enrich matches with location/body_part and convert to relative paths
|
| 290 |
# ================================================================
|
| 291 |
logger.info(" Adding location/body_part metadata...")
|
| 292 |
for match in matches:
|
|
|
|
| 295 |
)
|
| 296 |
match["location"] = location
|
| 297 |
match["body_part"] = body_part
|
| 298 |
+
# Convert absolute path to relative (portable across environments)
|
| 299 |
+
match["filepath"] = make_relative_path(match["filepath"], PROJECT_ROOT)
|
| 300 |
|
| 301 |
# ================================================================
|
| 302 |
# Set up cache directory
|
src/snowleopard_reid/cache.py
CHANGED
|
@@ -358,7 +358,13 @@ def generate_visualizations_from_npz(
|
|
| 358 |
for match in matches:
|
| 359 |
rank = match["rank"]
|
| 360 |
catalog_id = match["catalog_id"]
|
| 361 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 362 |
|
| 363 |
# Look for NPZ file by catalog_id
|
| 364 |
npz_path = pairwise_dir / f"{catalog_id}.npz"
|
|
|
|
| 358 |
for match in matches:
|
| 359 |
rank = match["rank"]
|
| 360 |
catalog_id = match["catalog_id"]
|
| 361 |
+
|
| 362 |
+
# Resolve relative path to absolute (handles both relative and absolute paths)
|
| 363 |
+
filepath = match["filepath"]
|
| 364 |
+
if not Path(filepath).is_absolute():
|
| 365 |
+
catalog_image_path = PROJECT_ROOT / filepath
|
| 366 |
+
else:
|
| 367 |
+
catalog_image_path = Path(filepath)
|
| 368 |
|
| 369 |
# Look for NPZ file by catalog_id
|
| 370 |
npz_path = pairwise_dir / f"{catalog_id}.npz"
|