Pass Run object between files

Pass Run object around to log from multiple Python files

When you create a run object:
1
run = neptune.init(project='my_workspace/my_project')
Copied!
You can pass it around and use it to populate functions’ parameters and perform logging from multiple Python files.
Let’s create a recipe for that:
main.py
1
# Import from file shown below
2
from utils import log_images_epoch
3
4
# Create run in project
5
run = neptune.init(project='my_workspace/my_project')
6
7
# Log metrics in the same file
8
run['train/acc'] = 0.95
9
run['train/f1'] = 0.65
10
11
# Log by using imported function, pass 'run'
12
log_images_epoch(run=run)
Copied!
utils.py
1
# 'run' is Neptune run
2
def log_images_epoch(run):
3
image1 = ...
4
image2 = ...
5
6
run['images/img_1'].upload(image1)
7
run['images/img_2'].upload(image2)
Copied!
In this way, you can work with a larger codebase and use logging from multiple Python files.
Last modified 1mo ago
Export as PDF
Copy link