Git Product home page Git Product logo

visdom-tutorial's Introduction

Visdom Tutorial

This is a simple tutorial to start using Visdom to plot graphs when using PyTorch.

Install

Install Visdom using pip

pip install visdom

or Anaconda

conda install -c conda-forge visdom

Start the server

To use vidsom, you need to start the visdom server first. Make sure the server is running before you run your algorithms!

Start the server with:

python -m visdom.server

Then, in your browser, you can go to:

http://localhost:8097

You will see the visdom interface:

visdom

Let's plot something!

This repository contains the code to train a simple image classifier (tutorial) and to produce some example plots with visdom.

VisdomLinePlotter

We first create a visdom object to make the calls for us. You can find this code in utils.py file:

from visdom import Visdom

class VisdomLinePlotter(object):
    """Plots to Visdom"""
    def __init__(self, env_name='main'):
        self.viz = Visdom()
        self.env = env_name
        self.plots = {}
    def plot(self, var_name, split_name, title_name, x, y):
        if var_name not in self.plots:
            self.plots[var_name] = self.viz.line(X=np.array([x,x]), Y=np.array([y,y]), env=self.env, opts=dict(
                legend=[split_name],
                title=title_name,
                xlabel='Epochs',
                ylabel=var_name
            ))
        else:
            self.viz.line(X=np.array([x]), Y=np.array([y]), env=self.env, win=self.plots[var_name], name=split_name, update = 'append')

To create a new plot or to add new data to an existing plot, we will call plot(var_name, split_name, title_name, x, y), with:

  • var_name: variable name (e.g. loss, acc)
  • split_name: split name (e.g. train, val)
  • title_name: titles of the graph (e.g. Classification Accuracy)
  • x: x axis value (e.g. epoch number)
  • y: y axis value (e.g. epoch loss)

Main process

In train.py we create the visdom object as a global variable:

import utils

if __name__ == "__main__":
    
    global plotter
    plotter = utils.VisdomLinePlotter(env_name='Tutorial Plots')

Now we can use plotter in any function to add data to our graphs.

In the training function we add the loss value after every epoch as:

plotter.plot('loss', 'train', 'Class Loss', epoch, losses.avg)

In the validation function we add the loss and the accuracy values as:

plotter.plot('loss', 'val', 'Class Loss', epoch, losses.avg)
plotter.plot('acc', 'val', 'Class Accuracy', epoch, acc)

And that's it! Simple, isn't it?

Now we can check the graphs at any point by visiting the visdom interface at http://localhost:8097 as long as the visdom server is still running.

visdom

visdom-tutorial's People

Contributors

noagarcia avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.