Harden operator tile background metadata
This commit is contained in:
@@ -21,6 +21,9 @@ from typing import Any, Iterable
|
||||
|
||||
DEFAULT_MANIFEST_PATH = Path("/app/storage/operator-data/operator_samples_manifest.json")
|
||||
DEFAULT_OUTPUT_DIR = Path("/app/storage/operator-data/yolo-building-tile-dataset")
|
||||
REFERENCE_AOI_CATEGORY = "reference_aoi"
|
||||
PURE_EMPTY_BACKGROUND_CATEGORY = "pure_empty_negative"
|
||||
SPARSE_BACKGROUND_CATEGORY = "sparse_building_context"
|
||||
rasterio: Any = None
|
||||
Window: Any = None
|
||||
Transformer: Any = None
|
||||
@@ -165,6 +168,18 @@ def background_negative_repeat_count(
|
||||
return max(1, background_negative_repeat)
|
||||
|
||||
|
||||
def background_category_for_sample(sample: dict[str, Any]) -> str:
|
||||
explicit_category = str(sample.get("background_category") or "").strip()
|
||||
if explicit_category:
|
||||
return explicit_category
|
||||
if str(sample.get("sample_role") or "reference") != "background_candidate":
|
||||
return REFERENCE_AOI_CATEGORY
|
||||
reference_feature_count = int(sample.get("reference_feature_count") or 0)
|
||||
if reference_feature_count <= 0:
|
||||
return PURE_EMPTY_BACKGROUND_CATEGORY
|
||||
return SPARSE_BACKGROUND_CATEGORY
|
||||
|
||||
|
||||
def resolve_manifest_path(raw: str, manifest_path: Path) -> Path:
|
||||
path = Path(raw)
|
||||
if path.exists():
|
||||
@@ -315,7 +330,7 @@ def export_sample_tiles(
|
||||
) -> list[dict[str, Any]]:
|
||||
sample_slug = str(sample["sample_slug"])
|
||||
sample_role = str(sample.get("sample_role") or "reference")
|
||||
background_category = str(sample.get("background_category") or "reference_aoi")
|
||||
background_category = background_category_for_sample(sample)
|
||||
split = "val" if sample_slug.lower() in val_slugs else "train"
|
||||
raster_path = resolve_manifest_path(str(sample["raster_path"]), manifest_path)
|
||||
reference_path = resolve_manifest_path(str(sample["reference_path"]), manifest_path)
|
||||
|
||||
Reference in New Issue
Block a user