How to use Neptune with argparse#
You can use Neptune to log parameters defined with argparse .
Before you start#
- Sign up at neptune.ai/register.
- Create a project for storing your metadata.
-
Have argparse and Neptune installed:
Upgrading with neptune-client
already installed
Important: To smoothly upgrade to the 1.0
version of the Neptune client library, first uninstall the neptune-client
library and then install neptune
.
Logging parameters with argparse#
-
Import Neptune and start a run:
-
If you haven't set up your credentials, you can log anonymously:
-
-
Specify and parse the arguments.
-
Log the parsed arguments to a namespace in the run:
Inside the namespace, Neptune creates a field for each argument.
-
To stop the connection to Neptune and sync all data, call the
stop()
method: -
Run your script as you normally would.
Sample output
https://app.neptune.ai/workspace-name/project-name/e/RUN-100/metadata
The general format is https://app.neptune.ai/<workspace>/<project>
followed by the Neptune ID of the initialized object.
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(
api_token="h0dHBzOi8aHR0cHM6Lkc78ghs74kl0jvYh3Kb8", # your token here
project="ml-team/classification", # your full project name here
)
- API token: In the bottom-left corner, expand the user menu and select Get my API token.
- 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!):
Follow the run link and explore the logged parameters in the All metadata dashboard.
Logging with Namespace()
#
You can also use Namespace()
to define the args:
from argparse import Namespace
args = Namespace(
lr=0.01,
batch=32,
activation="ReLU",
)
args = argparser.parse_args()
run["parameters"] = args
Related
- Log parameters and model config
- What you can log and display
- API reference ≫
assign()
- argparse in the Python documentation