#!/usr/bin/env bash
set -euo pipefail

seed=${1:-42}

export CUDA_VISIBLE_DEVICES="5,6"

DATA_PATH=${DATA_PATH:-"/path/to/COCO/val2014"}
COCO_ANN=${COCO_ANN:-"/path/to/COCO/annotations/instances_val2014.json"}
COCO_ANN_DIR=${COCO_ANN_DIR:-"/path/to/COCO/annotations"}
DEPTH_PATH=${DEPTH_PATH:-"/path/to/COCO_depth/val2014/npy"}

OUT_DIR="./output/CHAIR/mplug/base_vcd_opera"
RES_DIR="./result"
mkdir -p "$OUT_DIR" "$RES_DIR"

DSCR_ALPHA=${DSCR_ALPHA:-0.6}
DSCR_BETA=${DSCR_BETA:-0.55}
DSCR_SIGMA=${DSCR_SIGMA:-0.24}
DSCR_KEEP_RATIO=${DSCR_KEEP_RATIO:-0.8}
DSCR_LAMBDA=${DSCR_LAMBDA:-0.26}
DSCR_START=${DSCR_START:-12}
DSCR_END=${DSCR_END:-20}

python ./eval/chair_mplug_vcd_opera.py \
  --answers-file "$OUT_DIR/chair_mplug_dscr_seed${seed}.jsonl" \
  --data-path "$DATA_PATH" \
  --coco-ann-file "$COCO_ANN" \
  --depth-folder "$DEPTH_PATH" \
  --seed "$seed" \
  --use-dscr \
  --dscr-alpha ${DSCR_ALPHA} \
  --dscr-beta ${DSCR_BETA} \
  --dscr-sigma ${DSCR_SIGMA} \
  --dscr-keep-ratio ${DSCR_KEEP_RATIO} \
  --dscr-lambda ${DSCR_LAMBDA} \
  --dscr-start-layer ${DSCR_START} \
  --dscr-end-layer ${DSCR_END} \
  --dscr-key-only

python ./eval/chair.py \
  --cap_file "$OUT_DIR/chair_mplug_dscr_seed${seed}.jsonl" \
  --save_path "$RES_DIR/chair_mplug_dscr_seed${seed}.json" \
  --coco_path "$COCO_ANN_DIR"

python ./eval/chair_mplug_vcd_opera.py \
  --answers-file "$OUT_DIR/chair_mplug_opera_seed${seed}.jsonl" \
  --data-path "$DATA_PATH" \
  --coco-ann-file "$COCO_ANN" \
  --depth-folder "$DEPTH_PATH" \
  --seed "$seed" \
  --use-opera \
  --beam 5 \
  --scale_factor 50 \
  --threshold 15 \
  --num_attn_candidates 5 \
  --penalty_weights 1.0

python ./eval/chair.py \
  --cap_file "$OUT_DIR/chair_mplug_opera_seed${seed}.jsonl" \
  --save_path "$RES_DIR/chair_mplug_opera_seed${seed}.json" \
  --coco_path "$COCO_ANN_DIR"
