wandb一个简单demo

wandb绘制曲线:sin函数,cos函数,log函数。

wandb绘制本地图片

wandb绘制matplotlib图片

wandb绘制numpy图片

import math
import wandb
import matplotlib.pyplot as plt
import numpy as np


def wandb_curves():
    # 1. init wandb
    wandb.init(project="wandb_usage", name="curves_demo")

    # 2. log curves
    total_step_num = 100
    for step in range(total_step_num):
        wandb.log({'sin': math.sin((step + 1) / total_step_num * math.pi * 2)}, step=step + 1)
        wandb.log({'cos': math.cos((step + 1) / total_step_num * math.pi * 2)}, step=step + 1)
        wandb.log({'log': math.log(step + 1)}, step=step + 1)

    # 3. finish
    wandb.finish()


def wandb_imgs():
    # 1. init wandb
    wandb.init(project="wandb_usage", name="imgs_demo")

    # 2. log local imgs
    frames = []
    frames.append(wandb.Image('1.jpg', caption="local image"))  # 1.jpg is the local image
    wandb.log({'local img': frames})

    # 3. log matplotlib imgs
    frames = []
    plt.plot(np.random.rand(10))
    frames.append(wandb.Image(plt, caption="matplotlib image"))
    wandb.log({'matplotlib img': frames})

    # 4. log numpy imgs
    frames = []
    img = np.random.rand(100, 100, 3)
    frames.append(wandb.Image(img, caption="numpy image"))
    wandb.log({'numpy img': frames})

    # 5. finish
    wandb.finish()


if __name__ == '__main__':
    wandb_curves()
    wandb_imgs()

结果图:

wandb一个简单demo_第1张图片

你可能感兴趣的:(wandb)