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:
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
[neptune] [info ] Neptune initialized. Open in the app:
https://app.neptune.ai/workspace/project/e/RUN-1
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:
Alternatively, you can pass the information when using a function that takes api_token
and project
as 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:
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