Keras integration API reference
API reference for the Neptune-Keras integration.
You can use a Neptune callback to capture model training metadata when using TensorFlow with Keras.
NeptuneCallback
Captures model training metadata and logs them to Neptune.
Note
To use this package, you need to have Keras or TensorFlow 2 installed on your machine.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| run | RunorHandler | - | (required) An existing run reference, as returned byneptune.init_run(), or anamespace 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. Requirespydotto be installed. |
| log_on_batch | bool, optional | False | Log the metrics also for each batch, not only each epoch. |
| log_model_summary | bool, optional | True | Whether to log the model summary. |
Examples
Creating a Neptune run and callback
Create a run:
import neptune
run = neptune.init_run()
As a best practice, you should save your Neptune API token and project name as environment variables:
export NEPTUNE_API_TOKEN="h0dHBzOi8aHR0cHM6Lkc78ghs74kl0jv...Yh3Kb8"
export NEPTUNE_PROJECT="ml-team/classification"
Alternatively, you can pass the information when using a function that takesapi_tokenandprojectas arguments:
run = neptune.init_run(
api_token="h0dHBzOi8aHR0cHM6Lkc78ghs74kl0jv...Yh3Kb8", # (1)!
project="ml-team/classification", # (2)!
)
- In the bottom-left corner, expand the user menu and select Get my API token .
- You can copy the path from the project details ( → Details & privacy ).
If you haven't registered, you can log anonymously to a public project:
api_token=neptune.ANONYMOUS_API_TOKEN
project="common/quickstarts"
Make sure not to publish sensitive data through your code!
Instantiate the Neptune callback:
from neptune.integrations.tensorflow_keras import NeptuneCallback
neptune_callback = NeptuneCallback(run=run)
Pass the callback to thecallbacksargument of model.fit()
model.fit(x_train, 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(
run=run,
base_namespace="visualizations", # optionally set a custom namespace name
log_model_diagram=True,
log_on_batch=True,
)
...
See also
neptune-tensorflow-keras repo onGitHub
Related Documentation
This page is originally sourced from the legacy docs.