다음으로 하이퍼파라미터 설정 및 모델 학습을 진행해보겠습니다.
BATCH_SIZE = 64 # ①
EPOCHS = 120 # ②
SAVE_PATH = 'yolo.h5' # ③
def lr_schedule(epoch): # ④
if epoch < 75:
return 0.001 + 0.009 * (epoch / 75.0) # ⑤
elif epoch < 105:
return 0.001 # ⑥
else:
return 0.0001 # ⑦
def compile_and_train_model(model, train_data, val_data): # ⑧
checkpoint_callback = tf.keras.callbacks.ModelCheckpoint(
SAVE_PATH,
verbose=1,
save_best_only=True # ⑨
)
lr_callback = tf.keras.callbacks.LearningRateScheduler(lr_schedule) # ⑩
optimizer = tf.keras.optimizers.SGD(learning_rate=0.001, momentum=0.9) # ⑪
model.compile(loss=yolo_multitask_loss, optimizer=optimizer, run_eagerly=True)