Quickstart

Easily instrument a script to see our experiment tracking and visualization features on your own project

Start logging machine learning experiments in three quick steps.

1. Install Library

Install our library in an environment using Python 3.

pip install wandb

If you are training models in an automated environment where it's inconvenient to run shell commands, such as Google's CloudML, you should look at the documentation on Running in Automated Environments.

2. Create Account

Sign up for a free account in your shell or go to our sign up page.

wandb login

3. Modify your training script

Add a few lines to your script to log hyperparameters and metrics.

Weights and Biases is framework agnostic, but if you are using a common ML framework, you may find framework-specific examples even easier for getting started. We've built framework-specific hooks to simplify the integration for Keras, TensorFlow, PyTorch, Fast.ai, Scikit-learn, XGBoost, Catalyst, and Jax.

Initialize Wandb

Initialize wandb at the beginning of your script right after the imports.

# Inside my model training code
import wandb
wandb.init(project="my-project")

We automatically create the project for you if it doesn't exist. Runs of the training script above will sync to a project named "my-project". See the wandb.init documentation for more initialization options.

Declare Hyperparameters

It's easy to save hyperparameters with the wandb.config object.

wandb.config.dropout = 0.2
wandb.config.hidden_layer_size = 128

Log Metrics

Log metrics like loss or accuracy as your model trains (in many cases we provide framework-specific defaults). Log more complicated output or results like histograms, graphs, or images with wandb.log.

def my_train_loop():
for epoch in range(10):
loss = 0 # change as appropriate :)
wandb.log({'epoch': epoch, 'loss': loss})

Save Files

Anything saved in the wandb.run.dir directory will be uploaded to W&B and saved along with your run when it completes. This is especially convenient for saving the literal weights and biases in your model:

# by default, this will save to a new subfolder for files associated
# with your run, created in wandb.run.dir (which is ./wandb by default)
wandb.save("mymodel.h5")
‚Äč
# you can pass the full path to the Keras model API
model.save(os.path.join(wandb.run.dir, "mymodel.h5"))

Great! Now run your script normally and we'll sync the logs in a background process. Your terminal output, metrics, and files will be synced to the cloud, along with a record of your git state if you're running from a git repo.

If you're testing and want to disable wandb syncing, set the environment variable WANDB_MODE=dryrun