Welcome to pytorchart’s documentation!¶
FlexLoggers module¶
FlexLogger¶
Module for the FlexLogger Class
-
class
pytorchart.flexilogger.
FlexLogger
(plot_args, meter_args, **kwargs)[source]¶ Base object for logging. It takes some specifications for meters and for plots, indexes them, and adds a hook to send data to plots on log.
Parameters: - plot_args – dictionary of definitions for plotters or None.
- meter_args – dictionary of definitions for meters
- kwargs – additional keyword arguments
Examples:
meters = { 'mymetric': {'type': 'AverageValueMeter', 'target': 'misc'} 'test_loss': {'type': 'AverageValueMeter', 'target': 'loss'} 'train_loss': {'type': 'AverageValueMeter', 'target': 'loss'} # target is the plot key } plots = {'loss': {'type': 'line'}, 'misc': {'type': 'line'}} TM = FlexLogger(plots, meters, env='bob') # initializes plots with meters to visdom env 'bob' # sample expirement step - for more see unittests TM(mymetric=69, test_loss=0.94) TM.step() TM.log(reset=True) # log and reset
-
add_metrics_for
(*args, plot=None, phases=None)[source]¶ Adds some metrics to hte meter, with an optional target plot. If the plot already exists, they will be added there.
Parameters: - args – list of strings corresponding to metrics
- plot – string - name of plot
- phases – list of strings corresponding to phases
Returns: Example:
# create new flexlogger TM = FlexLogger.from_presets('acc') # ... do stuff # latter on, need to add some stuff to a new plot TM.add_metrics_for('loss', 'norm_loss', 'hinge_loss', 'demorgan_loss', plot='loss', phases=['test])
-
classmethod
from_presets
(*args, phases=None)[source]¶ Factory method to generate a logger from some preconfigured keys. see presets.preconfigured.Config for details
Parameters: - args –
- phases –
Returns: instance of Flexilogger
Example: TM = FlexLogger.from_presets('acc', 'loss')
-
log
(keys=None, reset=False, step=False)[source]¶ Retrieves current values of all meters, and plots at current timestep. log is used to keep familiarity with torchnet interface.
if the reset keyword is set to True, calls self.reset() if the step keyword is set to True, calls self.step()
Parameters: - keys – list of names of plots or None. If None, plots all keys.
- reset – reset meters after plotting
- step – increment counter after plotting
Returns: None
Example:
-
reset
(keys=None)[source]¶ Resets all of own meters. If keys kwd is specified, only resets the meters with those key names.
Parameters: keys – list[str] list of keys which will be reset. Returns: None
-
save
(file_path, plots=False)[source]¶ saves this object, and the visdom state if plots is True todo implement lol :return: None
-
show
(meta=False)[source]¶ Implementation for __repr__ with additional functionality. __repr__ shows only meters, but show gives options to show metadata for charts and meters.
Parameters: meta – (boolean) Returns: (string) detailed representation of self. Example:
# create Logger Stat = FlexLogger('loss', 'acc') Stat.show()
Output:
Plots: loss train_loss - AverageValueMeter : nan test_loss - AverageValueMeter : nan acc test_acc - AverageValueMeter : nan train_acc - AverageValueMeter : nan Not plotted:
-
step
(step=None)[source]¶ Increments the internal counter, or sets to value of :step arg
Parameters: step – (int) if step is specified, sets the internal counter to that step Returns: (int) updated step count
-
update_config
(plot_args, meter_args)[source]¶ Api for adding meters and plots.
Parameters: - plot_args –
- meter_args –
Returns:
-
vis
¶ property: Retrieve the Visdom() object for fun or profit
Returns: Visdom() object
ModelLogger¶
-
class
pytorchart.tooledmodel.
FlexTooledModel
(plot_args, metrics, model=None, **kwargs)[source]¶ Logging a nn.Module values to a Flexlogger by adding hooks.
nn.Modules natively give a forward and backward hook, which have a function signature of
forward_hook(module, input, output) -> None
backward_hook(module, grad_in, grad_out) -> grad
- This module will
- take a set of specifications for such functions,
- create hooks for them to nn.Module
- connect the hooks to meters, and updated without the FlexLogger(data=xx) calls.
- meters will per normal when using the FlexLogger.log()
Example:
-
register_model
(model, step_on_first=True)[source]¶ Registers a model to its hook functions. The hooks specs must already be registered in self
Parameters: model – nn.Module - Returns: - Usage:
my_spec = { 0:{‘grad_out’: [torch.mean], ‘weights’: [torch.std]}}
model = nn.Sequential(nn.Linear(20, 10), nn.Linear(10, 3)) TM = FlexTooledModel(model, spec=my_spec)
Loggers package¶
TraceLogger Class¶
-
class
pytorchart.Loggers.tracelogger.
TraceLogger
(*args, opts={}, vis=None, legend=[], env=None, port=8097, **kwargs)[source]¶ Logging arbitrary data by keys at runtime to a metering operation.
TraceLogger has the same idea as tnt.VisdomLogger, but with more access to plotly properties directly, with the downside of being less flexible. Also, it bypasses the visdom.scatter interface, and directly sends json data, so a few things which are rather difficult to do like specifing lines with a certain color and line style.
Though this is not meant to be used directly, it can be by all means:
Examples: -
log
(X, Y)[source]¶ Same interface as torchnet.log(), applies metadata to the X,Y Values, and sends them to the visdom plot.
Parameters: - X – list of integers - X-axis values of size self.num_lines
- Y – list of integers - X-axis values of size self.num_lines
Returns: None
-
save
(path)[source]¶ saves self, and saves the visdom enviornment.
Parameters: path – valid filepath Returns: None
-
viz
¶ retrieves the Visdom Object
Returns: visom.Visdom Object
-
pytorchart.moremeters package¶
pytorchart.moremeters.bestmeter module¶
pytorchart.moremeters.image_meter module¶
Module contents¶
pytorchart.presets package¶
Submodules¶
pytorchart.presets.functional module¶
-
class
pytorchart.presets.functional.
LayerLegend
[source]¶ Bases:
object
keeps track of layers and assigned Colors
-
pytorchart.presets.functional.
generate_layers
(model, colors=None, fn=None, targets=[])[source]¶ Parameters: - model –
- colors –
- fn –
- targets –
Returns:
-
pytorchart.presets.functional.
summarize
(model, fn=<function _identity>)[source]¶ Given a nn.Module, recursively walk its submodules and apply a function
Parameters: - model – nn.Module or superclass thereof
- fn – function to be applied to any module to create a summary
Returns: list of summaries generated by fn(module)
pytorchart.presets.preconfigured module¶
-
class
pytorchart.presets.preconfigured.
Config
[source]¶ Bases:
object
Static object for generating meter and plot configurations
-
classmethod
default_cfg
()[source]¶ return a the base configuration for plot and meter :return: dict
Usage: Config.default_cfg()
-
classmethod
gen_plot
(*keys, phases=None, plot=None)[source]¶ Creates a plot from the specified keys.
Parameters: - keys – list of strings
- phases – list of strings or None. If None, it will use default
phases of [‘test’, [‘train’] :param plot: name of plot
Returns: tuple of dicts for plots and meters
-
classmethod
get_presets
(*keys, phases=None)[source]¶ generate a dictionary of plots and meters given preconfigured keys. This will create a meter by key by phase.
Parameters: - keys – list of strings
- phases – list of strings or None. If None, it will use default
phases of [‘test’, [‘train’]
Returns: tuple of dicts for plots and meters
-
classmethod