visdom可视化loss曲线等在训练代码中应用

visdom可视化loss曲线等在训练代码中应用

visdom安装

pip installl visdom

可以向服务器提供以下选项:

-port:运行服务器的端口。
-hostname:运行服务器的主机名。
-base_url:基本服务器的URL(默认=/)。
-env_path:要重载的序列化会话的路径。
-logging_level:日志记录级别(默认=INFO)。接受标准文本和数字日志记录值。
-readonly:标记以只读模式启动服务器。
-enable_login:标记以设置服务器的身份验证,需要用户名和密码才能登录。
-force_new_cookie:标记以重置服务器使用的安全cookie,从而使当前的登录cookie无效。需要-enable_login开启。

当提供-enable_login标志时,服务器要求用户使用终端提示输入凭据。或者,你可以设置VISDOM_USE_ENV_CREDENTIALSenv变量,然后通过VISDOM_USERNAME和VISDOM_PASSWORDenv变量提供你的用户名和密码,无需手动与终端进行交互。

usage: visdom [-h] [-port port] [--hostname hostname]
              [-base_url base_url] [-env_path env_path]
              [-logging_level logger_level] [-readonly]
              [-enable_login] [-force_new_cookie]
              [-use_frontend_client_polling] [-bind_local]
              [-eager_data_loading]

Start the visdom server.

optional arguments:
  -h, --help            show this help message and exit
  -port port            port to run the server on.
  --hostname hostname   host to run the server on.
  -base_url base_url    base url for server (default = /).
  -env_path env_path    path to serialized session to
                        reload.
  -logging_level logger_level
                        logging level (default = INFO). Can
                        take logging level name or int
                        (example: 20)
  -readonly             start in readonly mode
  -enable_login         start the server with authentication
  -force_new_cookie     start the server with the new
                        cookie, available when -enable_login
                        provided
  -use_frontend_client_polling
                        Have the frontend communicate via
                        polling rather than over websockets.
  -bind_local           Make server only accessible only
                        from localhost.
  -eager_data_loading   Load data from filesystem when
                        starting server (and not lazily upon
                        first request).

代码中使用

  • 先开启visdom服务,在终端运行python -m visdom.server,在浏览器打开http://localhost:8097/

  • 训练代码中添加visdom

from visdom import Visdom
self.viz = Visdom(env="yht_win")

# 初始化
self.viz.line([0.], # y
            [0.], # x
            win="train_loss",
            name='loss',
            opts=dict(title="train_loss", xlabel='iters',ylabel='loss', legend=['loss']))
self.viz.line([0.], [0.], win="lr", name='lr',
    opts=dict(title="lr", xlabel='iters', ylabel='lr', legend=['lr']))
self.viz.line([[0., 0.]], [0.], win="f1&acc",
    opts=dict(title="f1&acc", xlabel='iters', ylabel='f1&acc', legend=['f1', "acc"]))

# 在训练代码中,将每一步更新的loss在窗口显示
self.viz.line([loss.cpu().detach().numpy()], [max_iter*epoch + i], 
                        win="train_loss", update="append", opts=dict(title="train_loss"))
# 一个窗口显示两条
self.viz.line([[mean_f1, mean_acc]], [max_iter*epoch+i], win="f1&acc", update="append", opts=dict(title="f1&acc"))
self.viz.line([lr], [max_iter*epoch+i], win="lr", update="append", opts=dict(title="lr"))

效果图

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_39506862/article/details/127897474
今日推荐