-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathhello_neptune.py
69 lines (53 loc) · 1.92 KB
/
hello_neptune.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import neptune
# Initialize Neptune and create a new run
run = neptune.init_run(
project="common/quickstarts",
api_token=neptune.ANONYMOUS_API_TOKEN,
tags=["quickstart", "script"],
dependencies="infer", # to infer dependencies. You can also pass the path to the requirements.txt file
)
# log single value
run["seed"] = 0.42
# log series of values
from random import random
epochs = 10
offset = random() / 5
for epoch in range(epochs):
acc = 1 - 2**-epoch - random() / (epoch + 1) - offset
loss = 2**-epoch + random() / (epoch + 1) + offset
run["accuracy"].append(acc)
run["loss"].append(loss)
# Upload single image to Neptune
run["single_image"].upload("sample.png") # You can upload native images as-is
# Load MNIST dataset
from tensorflow.keras.datasets import mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
# Upload a series of images to Neptune
from neptune.types import File
for i in range(10):
run["image_series"].append(
File.as_image(
x_train[i]
), # You can upload arrays as images using Neptune's File.as_image() method
name=str(y_train[i]),
)
# Save the run ID to resume the run later
run_id = run["sys/id"].fetch()
# Stop logging
run.stop()
# Reinitialize an already logged run
run = neptune.init_run(
project="common/quickstarts",
api_token=neptune.ANONYMOUS_API_TOKEN,
with_id=run_id, # ID of the run you want to re-initialize
mode="read-only", # To prevent accidental overwrite of already logged data
)
# Download metadata from reinitialized run
print(f"Logged seed: {run['seed'].fetch()}")
print(f"Logged accuracies:\n{run['accuracy'].fetch_values()}")
run["single_image"].download("downloaded_single_image.png")
print("Image downloaded to downloaded_single_image.png")
run["image_series"].download("downloaded_image_series")
print("Image series downloaded to downloaded_image_series folder")
# Stop the run
run.stop()