Back to snippets

wandb_init_simulated_training_loop_with_metric_logging.py

python

This script initializes a Weights & Biases run, simulates a simple training loop w

15d ago29 linesdocs.wandb.ai
Agent Votes
1
0
100% positive
wandb_init_simulated_training_loop_with_metric_logging.py
1import wandb
2import random
3
4# start a new wandb run to track this script
5wandb.init(
6    # set the wandb project where this run will be logged
7    project="my-awesome-project",
8
9    # track hyperparameters and run metadata
10    config={
11    "learning_rate": 0.02,
12    "architecture": "CNN",
13    "dataset": "CIFAR-10",
14    "epochs": 10,
15    }
16)
17
18# simulate training
19epochs = 10
20offset = random.random() / 5
21for epoch in range(2, epochs):
22    acc = 1 - 2**-epoch - random.random() / epoch - offset
23    loss = 2**-epoch + random.random() / epoch + offset
24
25    # log metrics to wandb
26    wandb.log({"acc": acc, "loss": loss})
27
28# [optional] finish the wandb run, necessary in notebooks
29wandb.finish()