wandb使用方法

wandb使用方法

oyxy2019 381 2023-05-03

官方文档地址:https://docs.wandb.ai/quickstart

安装
!pip install wandb
登录
import wandb

wandb.login(key="填入你的API Keys, 在官网的设置中找到")
初始化
import wandb

# 自定义一些本次训练的起始参数信息(数据集名称等等)(可选)
config = {
  "learning_rate": 0.001,
  "epochs": 100,
  "batch_size": 128,
  "image_size": 640
}

# 初始化(必填)
wandb.init(
    entity="zkhy",  # wandb上对应的team名称(必填)
    project="test-project",  # 本次的项目名称(必填)
    name="hello",  # 本次实验的名称(可选,如果不设置,wandb会自动生成本次实验名称)
    tags=["yolo", "lanes-detection"],  # 本次实验的标签(可选)
    notes="this is a training exp",  # 本次实验的备注(可选)
    config=config,  # 本次实验的配置说明(可选)
)
常见用法

记录数值信息wandb.log()

for i in range(epochs):
    # log中字典里的每一项都会生成一个图表信息
    wandb.log({
        "loss": random.randint(1, 6),
        "acc": random.randint(1, 100),
        "mAP.5": random.randint(10, 100)
    })

记录图像wandb.Image()

  • numpy:
for i in range(5):
    # 读取图片,读取的图片是numpy格式数组(HWC)
    img = plt.imread("../../left_color.png")
    # print(type(img), img.shape)
    wandb.log({
        "images": wandb.Image(img),  # 接收的是一个numpy格式的数组
        "images_r": wandb.Image(img[:, :, 0])  # 切其中一个通道上传
    })
  • plt:
import matplotlib.pyplot as plt

plt.plot([1, 2, 3, 4])
plt.ylabel("some interesting numbers")
wandb.log({"chart": plt})

参考:

http://t.csdn.cn/oCIts