Table of contents
Introduction to Weights & Biases
Weights & Biases is a powerful tool for deep learning visualization, which can realize the visualization of various parameters of deep learning and the optimization of deep learning hyperparameters. For detailed introduction, please see the official website.
https://wandb.ai/site Weights & Biases are implemented
in python using the wandb module
Use of Wandb
step1. Enter Weights & Biases to register and log in.
step2. Create project
step3. Install wandb
pip install wandb
step4. python program settings
- wandb initialization
wandb.init(project='VGG-LSTM',entity='ljhahaha')
- Hyperparameter settings
wandb.config.rnn_unit=64
wandb.config.lstm_layers=3
wandb.config.batch_size=128
wandb.config.lr=0.00001
wandb.config.epochs=30
wandb.config.optimizer='adam'
- Code body settings (optimizer settings are shown here)
optimizer = wandb.config.optimizer
if optimizer == "adam":
train_op = tf.train.AdamOptimizer(wandb.config.lr).minimize(softmaxs_loss)
elif optimizer == "sgd":
train_op = tf.train.GradientDescentOptimizer(wandb.config.lr).minimize(softmaxs_loss)
elif optimizer == "rmsprop":
train_op = tf.train.RMSPropOptimizer(wandb.config.lr).minimize(softmaxs_loss)
else:
raise ValueError("unexpected optimizer name")
- Parameter records (here shows the accuracy and loss function records of the training set and validation set during training)
#数据展示
wandb.log({
"Train Accuracy":acc_list,
"Train Loss":loss_list,
"Test Accuracy":val_acc,
"Test Loss":val_loss})
#画图展示
wandb.log({"loss" : wandb.plot.line_series(
xs=wandb.config.epochs,
ys=[loss_list, val_loss],
keys=["Loss of training", "Loss of validation"],
title="Loss function",
xname="epochs")})
wandb.log({"acc" : wandb.plot.line_series(
xs=wandb.config.epochs,
ys=[acc_list, val_acc],
keys=["Accuracy of training", "Accuracy of validation"],
title="Accuracy",
xname="epochs")})
step5. Sweep settings in Weights & Biases (for hyperparameter optimization)
- Create a new sweep
- Set sweep parameters.
When setting parameters, you can use a list to list the values, or you can choose the data distribution form.
Click the Sweep initializer below to get the following results:
3. Perform operations (all operations are performed in cmd)
代码展示
(1)Switch working path
cd E:/tensorflow_learning
(2) Wandb login
(3) Enter the API key (obtain the key according to the address given by him).
After entering the key, the system will automatically create a .netrc file
(4) Enter the agent command (ie the code in the launch agent), and the program will start. implement