Skip to content

API reference: Keras integration#

You can use a Neptune callback to capture model training metadata when using TensorFlow with Keras.


Captures model training metadata and logs them to Neptune.


To use this package, you need to have Keras or TensorFlow 2 installed on your machine.


Name         Type Default Description
run Run or Handler - (required) An existing run reference, as returned by neptune.init_run(), or a namespace handler.
base_namespace str, optional training Namespace under which all metadata logged by the Neptune callback will be stored.
log_model_diagram bool, optional False Save the model visualization. Requires pydot to be installed.
log_on_batch bool, optional False Log the metrics also for each batch, not only each epoch.


Creating a Neptune run and callback#

Create a run:

import neptune

run = neptune.init_run()
If Neptune can't find your project name or API token

As a best practice, you should save your Neptune API token and project name as environment variables:

export NEPTUNE_API_TOKEN="h0dHBzOi8aHR0cHM6Lkc78ghs74kl0jvYh3Kb8"
export NEPTUNE_PROJECT="ml-team/classification"

You can, however, also pass them as arguments when initializing Neptune:

run = neptune.init_run( # (1)!
    api_token="h0dHBzOi8aHR0cHM6Lkc78ghs74kl0jvYh3Kb8",  # your token here
    project="ml-team/classification",  # your full project name here
  1. Also works for init_model(), init_model_version(), and init_project().

  2. API token: In the bottom-left corner, expand the user menu and select Get my API token.

  3. Project name: in the top-right menu: Edit project details.

If you haven't registered, you can also log anonymously to a public project (make sure not to publish sensitive data through your code!):

run = neptune.init_run(

Instantiate the Neptune callback:

from neptune.integrations.tensorflow_keras import NeptuneCallback

neptune_callback = NeptuneCallback(run=run)

Pass the callback to the callbacks argument of, y_train, callbacks=[neptune_callback])

Logging with additional options#

import neptune
from neptune.integrations.tensorflow_keras import NeptuneCallback

run = neptune.init_run()

neptune_callback = NeptuneCallback(
    base_namespace="visualizations",  # optionally set a custom namespace name


See also

neptune-tensorflow-keras repo on GitHub