Skip to content
Edit on GitHub

Keras

DVCLive allows you to add experiment tracking capabilities to your Keras projects.

Usage

To start using DVCLive you just need to add a few lines to your training code in any Keras project.

Include the DvcLiveCallback int the callbacks list passed to your Model:

+from dvclive.keras import DvcLiveCallback

...

model.fit(
    train_dataset,
    epochs=num_epochs,
-    validation_data=validation_dataset)
+    validation_data=validation_dataset,
+    callbacks=[DvcLiveCallback()])

The history of each {metric} will be stored in:

{Live.dir}/scalars/{split}/{metric}.tsv

Where:

  • {Live.dir} is the dir attribute of Live.
  • {split} can be either train or eval.
  • {metric} is the name provided by the framework.

Without requiring additional modifications to your training code, you can use DVCLive alongside DVC. See DVCLive with DVC for more info.

Parameters

  • model_file - (None by default) - The name of the file where the model will be saved at the end of each step.

  • save_weights_only (False by default) - if True, then only the model's weights will be saved (model.save_weights(model_file)), else the full model is saved (model.save(model_file))

  • **kwargs - Any additional arguments will be passed to Live.

Examples

  • Using model_file and save_weights_only.
from dvclive.keras import DvcLiveCallback

model.fit(
    train_dataset,
    epochs=num_epochs,
    validation_data=validation_dataset,
    callbacks=[DvcLiveCallback(
        model_file="my_model_weights.h5",
        save_weights_only=True)])
  • Using **kwargs to customize Live.
from dvclive.keras import DvcLiveCallback

model.fit(
    train_dataset,
    epochs=num_epochs,
    validation_data=validation_dataset,
    callbacks=[DvcLiveCallback(
        model_file="my_model_weights.h5",
        path="custom_path")])
Content

🐛 Found an issue? Let us know! Or fix it:

Edit on GitHub

Have a question? Join our chat, we will help you:

Discord Chat