Skip to content

Instantly share code, notes, and snippets.

@gatheluck
Created June 5, 2019 01:32
Show Gist options
  • Save gatheluck/237d2bbec97be90e6ef6402a2f68e7e5 to your computer and use it in GitHub Desktop.
Save gatheluck/237d2bbec97be90e6ef6402a2f68e7e5 to your computer and use it in GitHub Desktop.
Plotting multiple loss by visdom with legend.
from visdom import Visdom
import argparse
import numpy as np
DEFAULT_PORT = 8097
DEFAULT_HOSTNAME = "http://localhost"
parser = argparse.ArgumentParser(description='Demo arguments')
parser.add_argument('-port', metavar='port', type=int, default=DEFAULT_PORT, help='port the visdom server is running on.')
parser.add_argument('-server', metavar='server', type=str, default=DEFAULT_HOSTNAME, help='Server address of the target to run the demo on.')
FLAGS = parser.parse_args()
viz = Visdom(port=FLAGS.port, server=FLAGS.server)
loss = np.array([1.2])
win = viz.line(
X=np.array([0]),
Y=np.column_stack((loss, loss)),
opts=dict(
xlabel='Epoch',
ylabel='Loss',
legend=['rec','seg']
)
)
for i in range(100):
viz.line(
X=np.array([i]),
Y=np.column_stack((np.array([1*i+loss]), np.array([2*i+loss]))),
win=win,
update='append'
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment