#!/bin/bash
set -e

: "${REC_CONFIG:=configs/rec/PP-OCRv5/PP-OCRv5_server_rec.yml}"
: "${DATA_ROOT:=../../train_data/japanese_ocr}"
: "${SAVE_DIR:=../../output/train/rec_product}"
: "${DICT_PATH:=${DATA_ROOT}/dict/ppocr_japanese_product_dict.txt}"
: "${LR:=0.0001}"
: "${REC_IMAGE_SHAPE:=3,48,320}"

echo "REC_CONFIG=${REC_CONFIG}"
echo "DATA_ROOT=${DATA_ROOT}"
echo "SAVE_DIR=${SAVE_DIR}"
echo "DICT_PATH=${DICT_PATH}"
echo "LR=${LR}"
echo "REC_IMAGE_SHAPE=${REC_IMAGE_SHAPE}"

python tools/train.py \
  -c "${REC_CONFIG}" \
  -o \
  Global.save_model_dir="${SAVE_DIR}" \
  Optimizer.lr.learning_rate="${LR}" \
  Global.character_dict_path="${DICT_PATH}" \
  Global.use_space_char=True \
  Architecture.Head.out_channels=0 \
  Train.dataset.data_dir="${DATA_ROOT}/rec" \
  Train.dataset.label_file_list="[${DATA_ROOT}/rec/rec_gt_train.txt]" \
  Eval.dataset.data_dir="${DATA_ROOT}/rec" \
  Eval.dataset.label_file_list="[${DATA_ROOT}/rec/rec_gt_val.txt]" \
  Transform.rec_image_shape="${REC_IMAGE_SHAPE}"
