#!/usr/bin/env bash # InsPLAD-det images from hf-mirror (Voxel51/InsPLAD), then build B_region. Run from code/ once SFID is unpacked to ../datasets/raw/sfid/SFID (needs curl and aria2c): # nohup bash fetch_insplad.sh > ../logs/insplad.log 2>&1 < /dev/null & # hf-mirror 302s these files to HF's Xet CDN, which answers 429 when pushed: few connections, pauses between passes. # ../runs/B_data/DONE (unblocks the target-domain jobs in queue.sh) is written only when every image is present. R=$(cd "$(dirname "$0")/.." && pwd) I=$R/datasets/raw/insplad_hf PY=${PY:-python} mkdir -p $I && cd $I || exit 1 for f in samples.json metadata.json; do [ -s $f ] || curl -s -L -A curl/8.0 -o $f "https://hf-mirror.com/datasets/Voxel51/InsPLAD/resolve/main/$f"; done while pgrep -u $USER -f "aria2c.*_urls.txt" > /dev/null; do sleep 30; done # a pass already in flight missing() { # writes missing_urls.txt, prints the count $PY -I - <<'PY' import json, urllib.parse from pathlib import Path det = [x for x in json.load(open("samples.json"))["samples"] if x["task"] == "detection"] bad = lambda p: not p.exists() or Path(f"{p}.aria2").exists() or p.stat().st_size < 10_000 # <10KB = error page miss = [x["filepath"] for x in det if bad(Path(x["filepath"]))] with open("missing_urls.txt", "w") as f: for p in miss: Path(p).unlink(missing_ok=True); Path(f"{p}.aria2").unlink(missing_ok=True) d, n = p.rsplit("/", 1) f.write(f"https://hf-mirror.com/datasets/Voxel51/InsPLAD/resolve/main/{urllib.parse.quote(p)}\n dir={d}\n out={n}\n") print(len(miss)) PY } for try in 1 2 3 4 5 6 7 8; do n=$(missing); echo "$(date +%T) pass $try: missing $n" [ "$n" = 0 ] && break aria2c -q -c -j 4 -x 1 --max-tries=5 --retry-wait=20 --file-allocation=none -i missing_urls.txt sleep 120 done n=$(missing); echo "$(date +%T) final: missing $n" cd $R/datasets && $PY -I $R/code/prepare_data.py region --raw raw/sfid/SFID --insplad raw/insplad_hf --out B_region || exit 1 [ "$n" = 0 ] && mkdir -p $R/runs/B_data && touch $R/runs/B_data/DONE