Skip to content

Commit 7f2ed01

Browse files
committed
Add pipeline.sh and fix bugs found in audit
1 parent eace10a commit 7f2ed01

4 files changed

Lines changed: 107 additions & 6 deletions

File tree

pipeline.sh

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
usage() {
5+
echo "Usage: $0 --mission <file.plan> --object <target> [--output-dir <dir>]"
6+
echo " $0 --image <image> --object <target> --scale x1 y1 x2 y2 [--output-dir <dir>]"
7+
exit 1
8+
}
9+
10+
SAM3_WEIGHTS="${SAM3_WEIGHTS:-$HOME/models/sam3}"
11+
GUROBI_LICENSE="${GUROBI_LICENSE:-$HOME/gurobi.lic}"
12+
OUTPUT_DIR=""
13+
MISSION=""
14+
IMAGE=""
15+
OBJECT=""
16+
SCALE_ARGS=""
17+
18+
while [[ $# -gt 0 ]]; do
19+
case $1 in
20+
--mission) MISSION="$2"; shift 2 ;;
21+
--image) IMAGE="$2"; shift 2 ;;
22+
--object) OBJECT="$2"; shift 2 ;;
23+
--output-dir) OUTPUT_DIR="$2"; shift 2 ;;
24+
--scale)
25+
if [[ $# -lt 5 ]]; then
26+
echo "Error: --scale requires 4 numbers (x1 y1 x2 y2)."
27+
exit 1
28+
fi
29+
SCALE_ARGS="--scale $2 $3 $4 $5"; shift 5 ;;
30+
*) echo "Unknown option: $1"; usage ;;
31+
esac
32+
done
33+
34+
if [ -z "$OBJECT" ]; then
35+
echo "Error: --object is required."
36+
usage
37+
fi
38+
39+
if [ -z "$MISSION" ] && [ -z "$IMAGE" ]; then
40+
echo "Error: --mission or --image is required."
41+
usage
42+
fi
43+
44+
if [ ! -d "$SAM3_WEIGHTS" ]; then
45+
echo "Error: SAM 3 weights not found at $SAM3_WEIGHTS"
46+
echo "Set SAM3_WEIGHTS env var to override."
47+
exit 1
48+
fi
49+
50+
if [ -z "${OPENAI_TOKEN:-}" ]; then
51+
echo "Error: OPENAI_TOKEN env var is not set."
52+
exit 1
53+
fi
54+
55+
# Mount the input file
56+
INPUT_FILE="${MISSION:-$IMAGE}"
57+
INPUT_BASENAME="$(basename "$INPUT_FILE")"
58+
INPUT_MOUNT="-v $(realpath "$INPUT_FILE"):/data/input/$INPUT_BASENAME:ro"
59+
if [ -n "$MISSION" ]; then
60+
LAMP_ARGS="--mission /data/input/$INPUT_BASENAME"
61+
else
62+
LAMP_ARGS="--image /data/input/$INPUT_BASENAME"
63+
fi
64+
LAMP_ARGS="$LAMP_ARGS --object $OBJECT --generate-waypoints $SCALE_ARGS"
65+
66+
# Output directory
67+
OUTPUT_MOUNT=""
68+
COPY_CMD=""
69+
if [ -n "$OUTPUT_DIR" ]; then
70+
mkdir -p "$OUTPUT_DIR"
71+
OUTPUT_MOUNT="-v $(realpath "$OUTPUT_DIR"):/data/output"
72+
COPY_CMD="cp -r /tmp/LAEP/* /data/output/ 2>/dev/null || true;"
73+
fi
74+
75+
# Gurobi license (optional but needed for optimizer)
76+
GUROBI_MOUNT=""
77+
if [ -f "$GUROBI_LICENSE" ]; then
78+
GUROBI_MOUNT="-v $(realpath "$GUROBI_LICENSE"):/opt/gurobi/gurobi.lic:ro"
79+
else
80+
echo "Warning: Gurobi license not found at $GUROBI_LICENSE — optimizer may fail."
81+
fi
82+
83+
docker run --gpus all --rm \
84+
-v "$SAM3_WEIGHTS":/weights \
85+
$GUROBI_MOUNT \
86+
$INPUT_MOUNT \
87+
$OUTPUT_MOUNT \
88+
-e OPENAI_TOKEN="$OPENAI_TOKEN" \
89+
${OPENAI_API_BASE:+-e OPENAI_API_BASE="$OPENAI_API_BASE"} \
90+
${OPENAI_MODEL:+-e OPENAI_MODEL="$OPENAI_MODEL"} \
91+
lamp bash -c "
92+
mkdir -p /tmp/LAEP && \
93+
cd /app/scripts && \
94+
python3 heat_map_gen.py $LAMP_ARGS && \
95+
python3 waypoint_scorer.py && \
96+
cd /app/optimization_core/build && \
97+
./main && \
98+
echo '[DONE] Pipeline complete.' && \
99+
$COPY_CMD
100+
echo 'Results in /tmp/LAEP/'
101+
"

run.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ docker run --gpus all -it --rm \
2525
-v "$SAM3_WEIGHTS":/weights \
2626
-v "$GUROBI_LICENSE":/opt/gurobi/gurobi.lic:ro \
2727
-e OPENAI_TOKEN="$OPENAI_TOKEN" \
28+
${OPENAI_API_BASE:+-e OPENAI_API_BASE="$OPENAI_API_BASE"} \
29+
${OPENAI_MODEL:+-e OPENAI_MODEL="$OPENAI_MODEL"} \
2830
lamp "$@"

scripts/heat_map_gen.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,8 @@ def get_ao_from_mission_file(file_path):
484484
full_heatmap_accumulator[y1:y2, x1:x2] -= binary_mask
485485

486486
successful_generations += 1
487-
487+
count_accumulator[y1:y2, x1:x2] += 1.0
488+
488489
# --- MEMORY CLEANUP ---
489490
del result, current_mask, binary_mask
490491
else:
@@ -494,9 +495,6 @@ def get_ao_from_mission_file(file_path):
494495
# --- MEMORY CLEANUP ---
495496
del result
496497

497-
# Increment the count for every pixel in this window
498-
count_accumulator[y1:y2, x1:x2] += 1.0
499-
500498
# Force Python to collect garbage, then empty the CUDA cache
501499
gc.collect()
502500
torch.cuda.empty_cache()

scripts/waypoint_scorer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ def load_plan_file(filepath):
124124

125125
except FileNotFoundError:
126126
print(f"[ERROR] Plan file not found at {filepath}")
127-
return None, None, None
127+
return None, None, None, None
128128
except json.JSONDecodeError:
129129
print(f"[ERROR] Failed to parse {filepath}. Ensure it is valid JSON.")
130-
return None, None, None
130+
return None, None, None, None
131131

132132

133133
def get_waypoint_scores(waypoint_list, inclusion_polygons, exclusion_polygons, heatmap_path, origin_lat, origin_lon, width_m, height_m, base_wp=None):

0 commit comments

Comments
 (0)