Search code examples
pythonpytorchwandb

How to get multiple lines exported to wandb


I am using the library weights and biases. My model outputs a curve (a time series). I'd like to see how this curve changes throughout training. So, I'd need some kind of slider where I can select epoch and it shows me the curve for that epoch. It could be something very similar to what it's done with histograms (it shows an image of the histograms across epochs and when you hover it display the histogram corresponding to that epoch). Is there a way to do this or something similar using wandb?

Currently my code looks like this:

for epoch in range(epochs):
   output = model(input)
   #output is shape (37,40) (lenght 40 and I have 37 samples)
   #it's enough to plot the first sample
   xs = torch.arange(40).unsqueeze(dim=1)
   ys = output[0,:].unsqueeze(dim=1)
   wandb.log({"line": wandb.plot.line_series(xs=xs, ys=ys,title="Out")}, step=epoch)

I'd appreciate any help! Thanks!


Solution

  • You can use wandb.log() with matplotlib. Create your plot using matplotlib:

    import matplotlib.pyplot as plt
    import numpy as np
    x = np.linspace(0, 50)
    for i in range(1, 4):
        fig, ax = plt.subplots()
        y = x ** i
        ax.plot(x, y)
        wandb.log({'chart': ax})
    

    Then when you look on your wandb dashboard for the run, you will see the plot rendered as plotly plot. Click the gear in the upper left hand corner to see a slider that lets you slide over training steps and see the plot at each step.