automl icon indicating copy to clipboard operation
automl copied to clipboard

I encounter the training divergence when finetuning

Open Jupanlee opened this issue 6 years ago • 2 comments

I encounter the training divergence when finetuning. I download pretrained efficientdet-d0, efficientdet-d1, ..., efficientdet-d7 from links in README.md ( 2. Pretrained Efficient Checkpoints ). And I finetune on my dataset based on the pretrained efficientdet-d0. Unfortunately, after several steps of training, NaN loss appeared and the training was terminated. Command I used for training is as follows:

#!/bin/bash
VERSION=$1
MODE=train_and_eval
TRAINING_FILE_PATTERN=tfrecord/decoration*.tfrecord
VALIDATION_FILE_PATTERN=tfrecord/decoration*.tfrecord
VAL_JSON_FILE=tfrecord/json_decoration.json
MODEL_NAME=efficientdet-d0
MODEL_DIR=./tmp/${MODEL_NAME}-scratch-decoration/${VERSION}
CKPT=efficientnet-b0
TRAIN_BATCH_SIZE=8
EVAL_BATCH_SIZE=8
EVAL_SAMPLES=512
NUM_EXAMPLES_PER_EPOCH=7072


python main.py --mode=${MODE} \
    --training_file_pattern=${TRAINING_FILE_PATTERN} \
    --validation_file_pattern=${VALIDATION_FILE_PATTERN} \
    --val_json_file=${VAL_JSON_FILE} \
    --model_name=${MODEL_NAME} \
    --model_dir=${MODEL_DIR} \
    --ckpt=${CKPT} \
    --train_batch_size=8 \
    --eval_batch_size=8 --eval_samples=512 \
    --num_examples_per_epoch=3022 --num_epochs=50  \
    --hparams="use_bfloat16=false,num_classes=9,moving_average_decay=0" \
    --use_tpu=False

Does anyone know what caused this ?

Jupanlee avatar Apr 12 '20 08:04 Jupanlee

I encountered the same problem when training on a custom dataset. Try reducing the learning rate. It worked for me to add learning_rate=0.001,lr_warmup_init=0.0001 to the --hparams

EDIT: I should probably also mention that the learning rate is proportional to the batch size. According to the det_model_fn.py the default batch size is 64. So if your batch size is 8 the effective learning rate is 8 times lower than you specified. Take that into account when selecting your learning rate.

Compuholic avatar Apr 16 '20 19:04 Compuholic

Close it due to out of date.

mingxingtan avatar May 12 '21 06:05 mingxingtan