Skip to content

Instantly share code, notes, and snippets.

@RishiRajak
Created July 12, 2021 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RishiRajak/a6ffa0a7c37c0abe723fc44dd8eb8c69 to your computer and use it in GitHub Desktop.
Save RishiRajak/a6ffa0a7c37c0abe723fc44dd8eb8c69 to your computer and use it in GitHub Desktop.
def compiler2(model,train_generator,valid_generator,epchs,bsize=32,lr=0.0001):
from tensorflow import keras as ks
callbck = ks.callbacks.EarlyStopping(monitor='val_loss',patience=10,
verbose=2,
restore_best_weights=True,)
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 = train_generator.n // 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