[PYTHON] Try using W & B

What is W & B

W&B The web version of the tensor board. You can see the differences on the online page, and you can also save the results of old experiments. This is a convenient site for recording machine learning logs and viewing results.

I will write an article referring to the following page. wandb Quickstart

setup

Use pip to install the wandb library.

pip install wandb

Since it is a web application, membership registration is required. It has a limited capacity, but is free for student and academic use. You can register from the following page. I can do it with my github account, so I was able to do it right away.

Membership registration page

At the terminal of the environment to be used next

wandb login

Then, the following page will appear.

wandb: You can find your API key in your browser here: https://app.wandb.ai/authorize
wandb: Paste an API key from your profile and hit enter:

When accessing the https://app.wandb.ai/authorize page from a PC with an account registered There is an API key of about 40 digits, so copy it and paste it at enter: above. This will link the server etc. with the web account.

Code rewriting

First, add the following code at the beginning.

# Inside my model training code
import wandb
wandb.init(project="my-project")

You can summarize the results by project name.

If there is an argument you want to save, you can save it with the config method.

wandb.config.dropout = 0.2
wandb.config.hidden_layer_size = 128

Next, enter the recording code in the training data.

def my_train_loop():
    for epoch in range(10):
        loss = 0 # change as appropriate :)
        wandb.log({'epoch': epoch, 'loss': loss})

Normally, put wandb.log ({dict}) in the part where print (loss) is performed. Graphs are created for the arguments passed in dict.

You can save the learning log by putting the following code at the end.

wandb.save("mymodel.h5")

Try to move

test.py


import wandb
wandb.init(project="test-project")

lr = 0.1
wandb.config.lr = lr

def my_train_loop():
    loss = 10

    for epoch in range(10):
        loss = loss * lr  # change as appropriate :)
        wandb.log({'epoch': epoch, 'loss': loss})
    wandb.save("mymodel.h5")


def main():
    my_train_loop()

if __name__ == "__main__":
    main()

Run the above code and When you access the W & B page,

スクリーンショット 2020-01-30 15.24.14.png

You can get the transition of loss like this. The reason why there is epoch is basically that the horizontal axis is the number of steps. Therefore, by recording epoch as the horizontal axis when creating a graph, スクリーンショット 2020-01-30 15.27.21.png In this way you can create graphs such as epoch vs loss.

The lr added to the config is also recorded, which is useful when reproducing. スクリーンショット 2020-01-30 15.30.01.png

it's simple.

Actually, it's the second day since I touched it, but there isn't much code to add, and it's quick to get a graph. Also, by recording on the web, you can collect and store the results on various servers in one. Please try it!

Recommended Posts

Try using W & B
Try using Tkinter
Try using docker-py
Try using cookiecutter
Try using geopandas
Try using Selenium
Try using scipy
Try using pandas.DataFrame
Try using django-swiftbrowser
Try using matplotlib
Try using tf.metrics
Try using PyODE
Try using virtualenv (virtualenvwrapper)
Try using virtualenv now
Try using Django templates.html
[Kaggle] Try using LGBM
Try using Python's feedparser.
Try using Python's Tkinter
Try using Tweepy [Python2.7]
Try using Pytorch's collate_fn
Try using PythonTex with Texpad.
[Python] Try using Tkinter's canvas
Try using Jupyter's Docker image
Try using scikit-learn (1) --K-means clustering
Try using matplotlib with PyCharm
Try using Azure Logic Apps
Try using Kubernetes Client -Python-
Try using the Twitter API
Try using OpenCV on Windows
Try using Jupyter Notebook dynamically
Try using AWS SageMaker Studio
Try tweeting automatically using Selenium.
Try using SQLAlchemy + MySQL (Part 1)
Try using the Twitter API
Try using SQLAlchemy + MySQL (Part 2)
Try using Django's template feature
Try using the PeeringDB 2.0 API
Try using Pelican's draft feature
Try using pytest-Overview and Samples-
Try using folium with anaconda
Try using Janus gateway's Admin API
Try using Spyder included in Anaconda
Try using design patterns (exporter edition)
Try using Pillow on iPython (Part 1)
Try using Pillow on iPython (Part 2)
Try using Pleasant's API (python / FastAPI)
Try using LevelDB in Python (plyvel)
Try using pynag to configure Nagios
Try using PyCharm's remote debugging feature
Try using ArUco on Raspberry Pi
Try using cheap LiDAR (Camsense X1)
[Sakura rental server] Try using flask.
Try using Pillow on iPython (Part 3)
Reinforcement learning 8 Try using Chainer UI
Try to get statistics using e-Stat
Try using Python argparse's action API
Try using the Python Cmd module
Try using Python's networkx with AtCoder
Try using Leap Motion in Python
Try using GCP Handwriting Recognition (OCR)
Try using Amazon DynamoDB from Python