#!/bin/bash
# Complete val split evaluation pipeline:
#   Step 1: Run inference on val split (skip if predictions already exist)
#   Step 2: Evaluate predictions against GT TFRecords

set -e

MODEL_PATH="output_models/dvlmad_waymo_dvlm_v2_32_lr1e-6_3361679/checkpoint-4510"
VAL_JSON="dvlmad_data/waymo_eval/dvlm-ad_waymo_e2e_val_cot_relative_cleaned.json"
IMAGE_ROOT="dvlmad_data"
PRED_OUTPUT_DIR="eval_outputs/waymo_val_5epochs_$(date +%Y%m%d_%H%M%S)"
GT_TFRECORDS="datasets/waymo-end-to-end/val*.tfrecord*"
EVAL_OUTPUT_DIR="./eval_results"

# ---- Step 1: Inference ----
echo "========================================"
echo "Step 1: Running inference on val split"
echo "========================================"
# python kewei_scripts/eval_dvlmad_waymo.py \
#     --model_path "$MODEL_PATH" \
#     --eval_json  "$VAL_JSON" \
#     --image_root "$IMAGE_ROOT" \
#     --output_dir "$PRED_OUTPUT_DIR" \
#     --num_gpus 8

# ---- Step 2: Evaluate ----

# conda activate autovla
echo ""
echo "========================================"
echo "Step 2: Computing ADE + RFS metrics"
echo "========================================"
python kewei_scripts/evaluate_waymo_v2.py \
    --pred_json   "$PRED_OUTPUT_DIR/predictions.json" \
    --gt_tfrecords "$GT_TFRECORDS" \
    --output_dir  "$EVAL_OUTPUT_DIR" \
    --save_gt_dict "$EVAL_OUTPUT_DIR/gt_dict_val.pkl"

echo ""
echo "Done. Results in $EVAL_OUTPUT_DIR"