wandb这个库可以帮助我们跟踪实验,记录运行中的超参数和输出指标,可视化结果并共享结果。
支持keras,tensorflow,scikit-learn,pytorch等
import wandb
# 1. Start a new run
wandb.init(project="gpt-3")
# 2. Save model inputs and hyperparameters
config = wandb.config
config.learning_rate = 0.01
# 3. Log gradients and model parameters
wandb.watch(model)
for batch_idx, (data, target) in
enumerate(train_loader):
if batch_idx % args.log_interval == 0:
# 4. Log metrics to visualize performance
wandb.log({"loss": loss})
下面是wandb的重要的工具:Dashboard:跟踪实验,可视化结果;Reports:分享,保存结果;Sweeps:超参调优;Artifacts:数据集和模型的版本控制。
Tools
- Dashboard: Track experiments, visualize results
- Reports: Save and share reproducible findings
- Sweeps: Optimize models with hyperparameter tuning
- Artifacts: Dataset and model versioning, pipeline tracking
一. 极简Lite Pipeline(6步用起来wandb)
https://wandb.ai/chuanqi/test
1 首先安装库:
pip install wandb
2 创建账户:
wandb login
3 import库再初始化:
# Inside my model training code
import wandb wandb.init(project=“my-project”)
4 声明超参数:
wandb.config.dropout = 0.2
wandb.config.hidden_layer_size = 128
5 记录日志:
def my_train_loop():
for epoch in range(10):
loss = 0 # change as appropriate :)
wandb.log({‘epoch’: epoch, ‘loss’: loss})
6 保存文件(默认在wandb.run.dir中):
# 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”))
使用wandb以后,模型输出,log和要保存的文件将会同步到cloud。