Skip to content

Commit 0a512f1

Browse files
authored
Create keras_callback.py
1 parent f41268f commit 0a512f1

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

keras_callback.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# import
2+
import keras
3+
4+
# Step 1: Defining the callbacks
5+
#------------------------------
6+
# define early stopping callback
7+
earlystopping = keras.callbacks.EarlyStopping(monitor='loss', patience=10)
8+
9+
# define model checkpoint callback
10+
checkpoint = ModelCheckpoint("checkpoint_model_{epoch:02d}.hdf5", monitor='loss', verbose=1, save_best_only=False, mode='auto', period=10)
11+
12+
# Step 2: Assigning the callback
13+
#------------------------------
14+
# fit the model
15+
history = model.fit(train_data_gen,
16+
# ....
17+
callbacks=[checkpoint, earlystopping]
18+
)

0 commit comments

Comments
 (0)