Skip to content

Instantly share code, notes, and snippets.

@TNick
Created March 23, 2015 23:49
Show Gist options
  • Save TNick/6b08190469a50ced8ed7 to your computer and use it in GitHub Desktop.
Save TNick/6b08190469a50ced8ed7 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
"""
Example functions for live_monitoring module (+/- part of pylearn2).
The examples in this file will not work with the live_monitoring.py
in GitHub repository. Instead, they are intended to work with the version
temporary hosted at https://gist.github.com/ead6e553fc5395449d03.git
Two variants of getting the data are presented.
With request-reply variant only one instance can connect to
that address:port while with publisher-subscriber variant there can
be multiple subscribers.
To be able to use these functions a LiveMonitoring extension must
be added to your train object:
# ...
live_u = LiveMonitoring()
experiment = Train(dataset=...,
model=...,
algorithm=...,
extensions=[..., live_u])
By default both variants are available. To disable pass 0 as the port:
# disable request-reply variant
live_u = LiveMonitoring(req_port=0)
# disable publisher-subscriber variant
live_u = LiveMonitoring(pub_port=0)
"""
from __future__ import print_function
__authors__ = "Nicu Tofan"
__credits__ = ["Nicu Tofan"]
__license__ = "3-clause BSD"
__email__ = "[email protected]"
from pylearn2.train_extensions.live_monitoring import LiveMonitor
def print_all_channels():
"""
This example retreives a list of channels from provided address.
The call is sequential - it will wait for the reply and return
the result as a ChannelsResponse instance.
ChannelsResponse.data may be an exception or a list of channel names.
"""
live = LiveMonitor(address="ec2-11-22-33-44.compute-1.amazonaws.com")
list_c = live.list_channels().data
if isinstance(list_c, Exception):
pass
else:
print(list_c)
def track_one_in_one_subplot():
"""
Track a single channel inside a single plot.
If Qt was not found follow_channels() logs a warning and
returns immediately.
"""
live = LiveMonitor(address="ec2-11-22-33-44.compute-1.amazonaws.com")
live.follow_channels(['momentum'], use_qt=True)
def track_mul_in_one_subplot():
"""
Tracks a number of channels inside a single plot.
If Qt was not found follow_channels() logs a warning and
returns immediately.
This function uses the request-reply variant.
"""
live = LiveMonitor(address="ec2-11-22-33-44.compute-1.amazonaws.com")
live.follow_channels(['momentum', 'train_objective'], use_qt=True)
def track_mul_in_mul_subplots():
"""
Tracks a number of channels inside a number of plots.
If Qt was not found follow_channels() logs a warning and
returns immediately.
This function uses the request-reply variant.
"""
live = LiveMonitor(address="ec2-11-22-33-44.compute-1.amazonaws.com")
chan_map = {'Title for first': ['train_layer_1_mean_x.max_u',
'train_layer_1_mean_x.mean_u',
'train_layer_1_mean_x.min_u'],
'Title for second': ['train_layer_2_mean_x.max_u',
'train_layer_2_mean_x.mean_u',
'train_layer_2_mean_x.min_u']}
live.follow_channels(chan_map, use_qt=True)
def subscribe_mul_in_one_subplot():
"""
Tracks a number of channels inside a number of plots.
If Qt was not found follow_channels() logs a warning and
returns immediately.
This function uses the publisher-subscriber variant.
"""
live = LiveMonitor(address="ec2-11-22-33-44.compute-1.amazonaws.com",
req_port=5556,
subscribe=True)
live.follow_channels(['momentum', 'train_objective'], use_qt=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment