torchnet.logger

Loggers provide a way to monitor your models. For example, the MeterLogger class provides easy meter visualizetion with Visdom , as well as the ability to print and save meters with the ResultsWriter class.

For visualization libraries, the current loggers support Visdom, although TensorboardX would also be simple to implement.

MeterLogger

class torchnet.logger.MeterLogger(server='localhost', env='main', port=8097, title='DNN', nclass=21, plotstylecombined=True)[source]

Bases: object

A class to package and visualize meters.

Parameters:
  • server – The uri of the Visdom server
  • env – Visdom environment to log to.
  • port – Port of the visdom server.
  • title – The title of the MeterLogger. This will be used as a prefix for all plots.
  • nclass – If logging for classification problems, the number of classes.
  • plotstylecombined – Whether to plot train/test curves in the same window.
peek_meter()[source]

Returns a dict of all meters and their values.

print_meter(mode, iepoch, ibatch=1, totalbatch=1, meterlist=None)[source]
reset_meter(iepoch, mode='Train')[source]
update_loss(loss, meter='loss')[source]
update_meter(output, target, meters={'accuracy'})[source]

VisdomLogger

Logging to Visdom server

class torchnet.logger.visdomlogger.BaseVisdomLogger(fields=None, win=None, env=None, opts={}, port=8097, server='localhost')[source]

Bases: torchnet.logger.logger.Logger

The base class for logging output to Visdom.

*THIS CLASS IS ABSTRACT AND MUST BE SUBCLASSED*

Note that the Visdom server is designed to also handle a server architecture, and therefore the Visdom server must be running at all times. The server can be started with $ python -m visdom.server and you probably want to run it from screen or tmux.

log(*args, **kwargs)[source]
log_state(state)[source]

Gathers the stats from self.trainer.stats and passes them into self.log, as a list

viz
class torchnet.logger.visdomlogger.VisdomLogger(plot_type, fields=None, win=None, env=None, opts={}, port=8097, server='localhost')[source]

Bases: torchnet.logger.visdomlogger.BaseVisdomLogger

A generic Visdom class that works with the majority of Visdom plot types.

log(*args, **kwargs)[source]
class torchnet.logger.visdomlogger.VisdomPlotLogger(plot_type, fields=None, win=None, env=None, opts={}, port=8097, server='localhost', name=None)[source]

Bases: torchnet.logger.visdomlogger.BaseVisdomLogger

log(*args, **kwargs)[source]
class torchnet.logger.visdomlogger.VisdomSaver(envs=None, port=8097, server='localhost')[source]

Bases: object

Serialize the state of the Visdom server to disk. Unless you have a fancy schedule, where different are saved with different frequencies, you probably only need one of these.

save(*args, **kwargs)[source]
class torchnet.logger.visdomlogger.VisdomTextLogger(fields=None, win=None, env=None, opts={}, update_type='REPLACE', port=8097, server='localhost')[source]

Bases: torchnet.logger.visdomlogger.BaseVisdomLogger

Creates a text window in visdom and logs output to it.

The output can be formatted with fancy HTML, and it new output can be set to ‘append’ or ‘replace’ mode.

Parameters:
  • fields – Currently not used
  • update_type – One of {‘REPLACE’, ‘APPEND’}. Default ‘REPLACE’.

For examples, make sure that your visdom server is running.

Example

>>> notes_logger = VisdomTextLogger(update_type='APPEND')
>>> for i in range(10):
>>>     notes_logger.log("Printing: {} of {}".format(i+1, 10))
# results will be in Visdom environment (default: http://localhost:8097)
log(msg, *args, **kwargs)[source]
valid_update_types = ['REPLACE', 'APPEND']