How to use Weights & Biases

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.

Insert image description here

step2. Create project

Insert image description here

step3. Install wandb

pip install wandb

step4. python program settings

  1. wandb initialization
wandb.init(project='VGG-LSTM',entity='ljhahaha')
  1. 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'
  1. 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")
  1. 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)

  1. Create a new sweep
  2. Set sweep parameters.
    When setting parameters, you can use a list to list the values, or you can choose the data distribution form.
    Insert image description here
    Click the Sweep initializer below to get the following results:
    Insert image description here3. Perform operations (all operations are performed in cmd)
代码展示

(1)Switch working path

cd E:/tensorflow_learning

(2) Wandb login
Insert image description here
(3) Enter the API key (obtain the key according to the address given by him).
Insert image description here
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
Insert image description here

step6. Enter the official website to view the running of the program

Insert image description here

Guess you like

Origin blog.csdn.net/LJ1120142576/article/details/119946090