#!/usr/bin/env bash

set -euo pipefail

ANALYSIS_REPORT=${ANALYSIS_REPORT:-/data1/dongying/Mono3d/G1Q3/model_inference/KPI/DL_KPI_SCENE/model_20260403_analysis/analysis_2d/mono3d_fp_fn-roi0/analysis_report.json}
CONFIG_PATH=${CONFIG_PATH:-eval_tools/configs/eval_config_yolov26s-roi0.yaml}
OUTPUT_BASE=${OUTPUT_BASE:-/data1/dongying/Mono3d/G1Q3/model_inference/KPI/DL_KPI_SCENE/model_20260403_analysis/analysis_2d/mono3d_fp_fn-roi0}
TOP_K=${TOP_K:-1000}

FN_ERROR_TYPES=(localization missing)
FP_ERROR_TYPES=(localization background)
CLASSES=(car)

for mode in fn fp; do
  if [[ "${mode}" == "fn" ]]; then
    ERROR_TYPES=("${FN_ERROR_TYPES[@]}")
  else
    ERROR_TYPES=("${FP_ERROR_TYPES[@]}")
  fi

  for error_type in "${ERROR_TYPES[@]}"; do
    for class_name in "${CLASSES[@]}"; do
      output_dir="${OUTPUT_BASE}/${mode}_${error_type}_vis_${class_name}"

      echo "============================================================"
      echo "Running visualization"
      echo "  mode:       ${mode}"
      echo "  error_type: ${error_type}"
      echo "  class:      ${class_name}"
      echo "  output:     ${output_dir}"
      echo "============================================================"

      python eval_tools/analysis/visualize_2d_fn_cases.py \
        --analysis-report "${ANALYSIS_REPORT}" \
        --config "${CONFIG_PATH}" \
        --mode "${mode}" \
        --error-types "${error_type}" \
        --classes "${class_name}" \
        --top-k "${TOP_K}" \
        --output-dir "${output_dir}"
    done
  done
done
