File size: 3,169 Bytes
61e89b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env bash
set -euo pipefail

# Bootstrap downloader: iterates used_scenes.json and downloads each scene.

# Resolve paths relative to this script
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DOWNLOAD_SCRIPT="${DOWNLOAD_SCRIPT:-${SCRIPT_DIR}/download.py}"
USED_SCENES_JSON="${USED_SCENES_JSON:-${SCRIPT_DIR}/used_scenes_test.json}" # Change to used_scenes.json for full download
GOOD_SCENES_DIR="${GOOD_SCENES_DIR:-${SCRIPT_DIR}/good_scenes}"

usage() {
  echo "Usage: $0 [-o OUTPUT_DIR]" >&2
  echo "  -o, --output   Output base dir for downloads (default: ${GOOD_SCENES_DIR})" >&2
}

while [[ $# -gt 0 ]]; do
  case "$1" in
    -o|--output)
      GOOD_SCENES_DIR="$2"; shift 2 ;;
    -h|--help)
      usage; exit 0 ;;
    *)
      echo "Unknown argument: $1" >&2; usage; exit 1 ;;
  esac
done

if [[ ! -f "$DOWNLOAD_SCRIPT" ]]; then
  echo "ERROR: download script not found at $DOWNLOAD_SCRIPT" >&2
  exit 1
fi

if [[ ! -f "$USED_SCENES_JSON" ]]; then
  echo "ERROR: used scenes JSON not found at $USED_SCENES_JSON" >&2
  exit 1
fi

mkdir -p "$GOOD_SCENES_DIR"

echo "Downloading scenes into: $GOOD_SCENES_DIR"

successful_downloads=0
total_scenes=0

# Extract tab-separated batch and hash for each scene from JSON
while IFS=$'\t' read -r batch hash scale; do
  [[ -z "$batch" || -z "$hash" ]] && continue
  total_scenes=$((total_scenes + 1))

  # echo "Saving metric $scale to text file"
  # echo "$scale" > "${GOOD_SCENES_DIR}/${batch}/${hash}/metric_scale.txt"

  echo "Downloading scene hash=$hash (batch=$batch) ..."

  scene_success=true

  # 1) images+poses at 4K and 960P
  for reso in 4K 960P; do
    if python3 "$DOWNLOAD_SCRIPT" \
              --odir "$GOOD_SCENES_DIR" \
              --subset "$batch" \
              --resolution "$reso" \
              --file_type "images+poses" \
              --hash "$hash" \
              --clean_cache; then
      echo "Successfully downloaded images+poses ($reso) for scene $hash"
    else
      echo "Failed to download images+poses ($reso) for scene $hash" >&2
      scene_success=false
    fi
  done

  # 2) colmap_cache (resolution arg required but not used)
  if python3 "$DOWNLOAD_SCRIPT" \
            --odir "$GOOD_SCENES_DIR" \
            --subset "$batch" \
            --resolution "4K" \
            --file_type "colmap_cache" \
            --hash "$hash" \
            --clean_cache; then
    echo "Successfully downloaded colmap_cache for scene $hash"
  else
    echo "Failed to download colmap_cache for scene $hash" >&2
    scene_success=false
  fi

  if [[ "$scene_success" == true ]]; then
    echo "Successfully downloaded all assets for scene $hash"
    successful_downloads=$((successful_downloads + 1))
  else
    echo "Scene $hash completed with some failures" >&2
  fi
done < <(python3 - "$USED_SCENES_JSON" << 'PY'
import json, sys
path = sys.argv[1]
with open(path, 'r') as f:
    data = json.load(f)
for s in data:
    batch = s.get('batch')
    hashv = s.get('hash')
    scale = s.get('scale', '1.0')
    if batch and hashv:
        print(f"{batch}\t{hashv}\t{scale}")
PY
)

echo "Summary: $successful_downloads/$total_scenes scenes downloaded successfully."