Skip to content

Pass run object between functions#

Once you've created a run with the init_run() function, you can pass it to functions from other files. This way, you can work with a larger codebase.

Example#

# Import from "utils.py" file
from utils import log_images_epoch

# Create run in project
run = neptune.init_run() # (1)!

# Log metrics in the same file
run["train/acc"] = 0.95
run["train/f1"] = 0.65

# Log by using an imported function, passing "run" as the argument
log_images_epoch(run=run)
  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",
    )
    
# "run" is the Neptune run
def log_images_epoch(run):
    image1 = ...
    image2 = ...

    run["images/img_1"].upload(image1)
    run["images/img_2"].upload(image2)