data_loader: auto-download ground_truth from HF Dataset at startup
Browse files- app/utils/data_loader.py +18 -1
app/utils/data_loader.py
CHANGED
|
@@ -66,7 +66,24 @@ def ensure_ground_truth(root: str) -> str:
|
|
| 66 |
|
| 67 |
# Try extracting from ground_truth.zip
|
| 68 |
zip_path = os.path.join(root, "ground_truth.zip")
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
logger.info(f"Extracting ground_truth.zip ({os.path.getsize(zip_path)//1e6:.0f} MB)...")
|
| 71 |
os.makedirs(gt_dir, exist_ok=True)
|
| 72 |
try:
|
|
|
|
| 66 |
|
| 67 |
# Try extracting from ground_truth.zip
|
| 68 |
zip_path = os.path.join(root, "ground_truth.zip")
|
| 69 |
+
|
| 70 |
+
# If not local, try downloading from HF Dataset (for HF Space deployment)
|
| 71 |
+
if not (os.path.exists(zip_path) and os.path.getsize(zip_path) > 10000):
|
| 72 |
+
try:
|
| 73 |
+
from huggingface_hub import hf_hub_download
|
| 74 |
+
logger.info("Downloading ground_truth.zip from HF Dataset Valmbd/petimot-ground-truth ...")
|
| 75 |
+
zip_path = hf_hub_download(
|
| 76 |
+
repo_id="Valmbd/petimot-ground-truth",
|
| 77 |
+
filename="ground_truth.zip",
|
| 78 |
+
repo_type="dataset",
|
| 79 |
+
local_dir=root,
|
| 80 |
+
)
|
| 81 |
+
logger.info(f"Downloaded ground_truth.zip: {os.path.getsize(zip_path)//1e6:.0f} MB")
|
| 82 |
+
except Exception as e:
|
| 83 |
+
logger.warning(f"Could not download ground_truth from dataset: {e}")
|
| 84 |
+
_gt_extracted_flag[gt_dir] = True
|
| 85 |
+
return gt_dir
|
| 86 |
+
|
| 87 |
logger.info(f"Extracting ground_truth.zip ({os.path.getsize(zip_path)//1e6:.0f} MB)...")
|
| 88 |
os.makedirs(gt_dir, exist_ok=True)
|
| 89 |
try:
|