Skip to main content

A wrapper to use visdom with python 'with' statement.

Project description

visdom-wrapper

A wrapper to use visdom with python 'with' statement.

Setup

pip3 install visdom-wrapper

Example

import numpy as np
import time
import os.path
import getpass
from sys import platform as _platform
from six.moves import urllib

from visdom_wrapper import VizWrapper
from visdom import  Visdom

# Images
for i in range(5):
    var = np.random.randn(20, 3, 64, 64)
    with VizWrapper("random_images") as viz_wrapper:
        viz_wrapper.update_wins(
            viz_wrapper.viz.images(var,
                                   opts=dict(title=viz_wrapper.name),
                                   win=viz_wrapper.win)) # Indispensable
    time.sleep(1)

# Change server port
VizWrapper.viz = Visdom(port=8098, server="http://localhost")

for i in range(5):
    var = np.random.randn(10, 3, 64, 64)
    with VizWrapper("random_images_1") as viz_wrapper:
        viz_wrapper.update_wins(
            viz_wrapper.viz.images(var,
                                   opts=dict(title=viz_wrapper.name),
                                   win=viz_wrapper.win)) # Indispensable
    time.sleep(1)

# Histogram
for i in range(5):
    var = np.random.rand(10000)
    with VizWrapper("histogram") as viz_wrapper:
        viz_wrapper.update_wins(
            viz_wrapper.viz.histogram(X=var,
                                      opts=dict(numbins=20),
                                      win=viz_wrapper.win)) # Indispensable
    time.sleep(1)

# Line updates
X = np.column_stack((np.arange(0, 10), np.arange(0, 10)))
Y = np.column_stack((np.linspace(5, 10, 10), np.linspace(5, 10, 10) + 5))
with VizWrapper("line") as viz_wrapper:
    viz_wrapper.update_wins(
        viz_wrapper.viz.line(X=X,
                             Y=Y,
                             win=viz_wrapper.win)) # Indispensable
time.sleep(2)
X = np.column_stack((np.arange(10, 20), np.arange(10, 20)))
Y = np.column_stack((np.linspace(5, 10, 10), np.linspace(5, 10, 10) + 5))
with VizWrapper("line") as viz_wrapper:
    viz_wrapper.update_wins(
        viz_wrapper.viz.line(X=X,
                             Y=Y,
                             win=viz_wrapper.win, # Indispensable
                             update='append'))

# Video
video = np.empty([256, 250, 250, 3], dtype=np.uint8)
for n in range(256):
    video[n, :, :, :].fill(n)
with VizWrapper("vedio") as viz_wrapper:
    viz_wrapper.update_wins(
        viz_wrapper.viz.video(tensor=video,
                              win=viz_wrapper.win)) # Indispensable


video_url = 'http://media.w3.org/2010/05/sintel/trailer.ogv'
# linux
if _platform == "linux" or _platform == "linux2":
    videofile = '/home/%s/trailer.ogv' % getpass.getuser()
# MAC OS X
elif _platform == "darwin":
    videofile = '/Users/%s/trailer.ogv' % getpass.getuser()
# download video
urllib.request.urlretrieve(video_url, videofile)

if os.path.isfile(videofile):
    with VizWrapper("vedio_1") as viz_wrapper:
        viz_wrapper.update_wins(
            viz_wrapper.viz.video(videofile=videofile,
                                  win=viz_wrapper.win)) # Indispensable

With visdom-wrapper, you can use visdom in a more convinent way.

  1. you don't have to create Visdom object explicitly.
  2. you don't have to manage visdom windows explicitly. VizWrapper with the same name will be updated to the same visdom window implicitly.
  3. all visdom apis are still avaiable and you can still configure visdom in a flexiable way.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

visdom-wrapper-0.1.0.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

visdom_wrapper-0.1.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file visdom-wrapper-0.1.0.tar.gz.

File metadata

  • Download URL: visdom-wrapper-0.1.0.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.4

File hashes

Hashes for visdom-wrapper-0.1.0.tar.gz
Algorithm Hash digest
SHA256 dd52049f06c305efd2c2cee61b58f5eb714cdc00a01b1c0a14218a7d48891af5
MD5 360ea803f366dd24f292ce0a81304969
BLAKE2b-256 8cc091bcdc7d41f892bf40833370159cba291073755b77381a779230e5a316d0

See more details on using hashes here.

File details

Details for the file visdom_wrapper-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: visdom_wrapper-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.4

File hashes

Hashes for visdom_wrapper-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 68306667ad90fa58d6d4ae78292449e0048307022a0444d7beed4fe08813e5da
MD5 646f6f47bf7ed124846d2b16e4c1384f
BLAKE2b-256 3bdb6d12a4faeff327b97333347ac4f29eb6a1f8ec4801ab767e452917f0ffe8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page