Last active
July 10, 2021 09:27
-
-
Save RishiRajak/fd7c2462518f51361a1d8bbc1108b4b9 to your computer and use it in GitHub Desktop.
Compile Model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def compiler2(model,train_generator,valid_generator,epchs,bsize,lr=0.0001): | |
from tensorflow import keras as ks | |
callbck = ks.callbacks.EarlyStopping(monitor='val_loss',patience=8,verbose=2,restore_best_weights=True) | |
#red_lr= ReduceLROnPlateau(monitor='val_acc',patience=3,verbose=1,factor=0.1) | |
opt = ks.optimizers.Adam(learning_rate=lr) | |
model.compile(loss="categorical_crossentropy", | |
optimizer=opt, | |
metrics=["accuracy"]) | |
history = model.fit(train_generator, | |
epochs=epchs, | |
callbacks=[callbck], | |
validation_data=valid_generator, | |
verbose = 1, | |
steps_per_epoch = 6552 // bsize) | |
#Visualise curves | |
plt.plot(history.history['accuracy'], label='train_acc') | |
plt.plot(history.history['val_accuracy'], label='valid_acc') | |
plt.title('lrate='+str(lr), pad=-50) | |
plt.legend() | |
plt.grid(True) | |
return model,history |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment