Skip to content

Using Neptune#

Basic usage

Import the Neptune client library
import neptune
Start a run (tracks duration, owner, entrypoint script, system metrics, Git info)
run = neptune.init_run() # (1)!
  1. We recommend saving your API token and project name as environment variables.

    If needed, you can pass them as arguments when initializing Neptune:

    neptune.init_run(
        project="workspace-name/project-name",
        api_token="YourNeptuneApiToken",
    )
    
Start a run (with customized details and tracking of additional source files and requirements)
run = neptune.init_run(
    name="blobfish-candytuft", # (1)!
    tags=["maskRCNN", "finetune"],
    source_files=["**/*.py", "config.yaml"],
    dependencies="infer",
)
  1. Sets a custom name, which you can use as a human-friendly ID.

    To display it in the app, add sys/name as a column.

    You can also edit the name in the run information view ( Run information).

Log metadata
run["your/structure"] = some_value

run["data/sample"].upload("figure/object/or/path/to/file")
run["data/train/samples/images"].upload_files("path/to/directory")
run["data/train/version"].track_files("path/to/artifacts")

for epoch in range(100):
    # your training loop
    loss = ...
    run["train/loss"].append(loss)
When you've captured all the model-building metadata you need, stop the run
run.stop()

Tutorials#

For detailed walkthroughs and use cases, check the Tutorials section.

Each tutorial comes with Jupyter notebooks or scripts (usually both) as well as examples in the Neptune web app.

Code examples on GitHub#

In the neptune-ai/examples repo on GitHub, you can browse our full library of example scripts, notebooks, use cases, and Neptune projects.

View examples repository 

Neptune demo project#

To get an idea of what a Neptune project can be used for, you can browse the showcase/onboarding-project sample project. It's set up for image segmentation.

To see how the metadata was logged, take a look at the train.py script in the Source code tab.

Browse example project