Sign inSign up

doctorai/keras-training-module

By doctorai

•Updated almost 6 years ago

Image
0

119

doctorai/keras-training-module repository overview

⁠Transfer_learning_with_keras Training Module

⁠Tensorflow 2 supported

⁠How to save model and visualize on tensorboard.

⁠Using Callbacks in model.fit()

from tensorflow.keras.callbacks import LearningRateScheduler, ModelCheckpoint, TensorBoard, ReduceLROnPlateau

callbacks = [
    ModelCheckpoint(
        os.path.join(checkpoint_path, CHECK_POINT),
        monitor="val_loss",
        verbose=1,
        save_best_only=True,
        mode="auto"
        ),
    TensorBoard(log_dir= os.path.join(log_path,run_id) )
    ]

hist = model.fit(
    train_generator,
    callbacks = callbacks,
    batch_size=16,
    steps_per_epoch = 10,
    epochs=nb_epochs,
    validation_data=eval_generator,
    shuffle=True,
    validation_steps=2,
    )
  • ModelCheckpoint - saving a model checkpoint best model only at every checkpoint.
  • TensorBoard - Saving Training meta-data so we can visualize train and validation graph for loss and accuracy.

⁠command to visualize tensorboard.

$ tensorboard dev upload --logdir path-to-log

⁠Saving and loading model

  • save model weights and model architecture in separate files.
  • save model architecture in both YAML and JSON format.
  • save model weights and architecture into a single file for later use.

⁠Saving History loss and accuracy in csv

hist = model.fit(
    train_generator,
    callbacks = callbacks,
    batch_size=16,
    steps_per_epoch = 10,
    epochs=nb_epochs,
    validation_data=eval_generator,
    shuffle=True,
    validation_steps=2,
    )
pd.DataFrame(hist.history).to_csv(os.path.join(destination,HISTORY_FILE))

Tag summary

Content type

Image

Digest

Size

1.9 GB

Last updated

almost 6 years ago

docker pull doctorai/keras-training-module