flambe.logging

Package Contents

class flambe.logging.TrialLogging(log_dir: str, verbose: bool = False, root_log_level: Optional[int] = None, capture_warnings: bool = True, console_prefix: Optional[str] = None, hyper_params: Optional[Dict] = None)[source]
__enter__(self)
__exit__(self, exc_type: Any, exc_value: Any, traceback: Any)

Close the listener and restore original logging config

flambe.logging.setup_global_logging(console_log_level: int = logging.NOTSET) → None[source]

Set up flambe logging with a Stream handler and a Rotating File handler.

This method should be set before consuming any logger as it sets the basic configuration for all future logs.

After executing this method, all loggers will have the following handlers: * Stream handler: prints to std output all logs that above The console_log_level * Rotating File hanlder: 10MB log file located in Flambe global folder. Configured to store all logs (min level DEBUG)

Parameters:console_log_level (int) – The minimum log level for the Stream handler
class flambe.logging.ScalarT[source]

Bases: typing.NamedTuple

A single scalar value

Supported by TensorboardX

Parameters:
  • tag (str) – Data identifier
  • scalar_value (float) – The scalar value
  • global_step (int) – Iteration associated with this value
  • walltime (float = time.time()) – Wall clock time associated with this value
tag :str
scalar_value :float
global_step :int
walltime :float
__repr__(self)
class flambe.logging.ScalarsT[source]

Bases: typing.NamedTuple

A dictionary mapping tag keys to scalar values

Supported by TensorboardX

Parameters:
  • main_tag (str) – Parent name for all the children tags
  • tag_scalar_dict (Dict[str, float]) – Mapping from scalar tags to their values
  • global_step (int) – Iteration associated with this value
  • walltime (float = time.time()) – Wall clock time associated with this value
main_tag :str
tag_scalar_dict :Dict[str, float]
global_step :int
walltime :float
__repr__(self)
class flambe.logging.HistogramT[source]

Bases: typing.NamedTuple

A histogram with an array of values

Supported by TensorboardX

Parameters:
  • tag (str) – Data identifier
  • values (Union[torch.Tensor, numpy.array]) – Values to build histogram
  • global_step (int) – Iteration associated with this value
  • bins (str) – Determines how bins are made
  • walltime (float = time.time()) – Wall clock time associated with this value
tag :str
values :Union[torch.Tensor, numpy.array]
global_step :int
bins :str
walltime :float
__repr__(self)
class flambe.logging.TextT[source]

Bases: typing.NamedTuple

Text message

Supported by TensorboardX

Parameters:
  • tag (str) – Data identifier
  • text_string (str) – String to record
  • global_step (int) – Iteration associated with this value
  • walltime (float) – Wall clock time associated with this value
tag :str
text_string :str
global_step :int
walltime :float
__repr__(self)
class flambe.logging.ImageT[source]

Bases: typing.NamedTuple

Image message

Supported by TensorboardX

Parameters:
  • tag (str) – Data identifier
  • img_tensor (Union) – Image tensor to record
  • global_step (int) – Iteration associated with this value
  • walltime (float) – Wall clock time associated with this value
tag :str
img_tensor :Union[torch.Tensor, numpy.array]
global_step :int
walltime :float
__repr__(self)
class flambe.logging.PRCurveT[source]

Bases: typing.NamedTuple

PRCurve message

Supported by TensorboardX

Parameters:
  • tag (str) – Data identifier
  • labels (Union[torch.Tensor, numpy.array]) – Containing 0, 1 values
  • predictions (Union[torch.Tensor, numpy.array]) – Containing 0<=x<=1 values. Needs to match labels size
  • num_thresholds (int = 127) – The number of thresholds to evaluate. Max value allowed 127.
  • weights (Optional[float] = None) – No description provided.
  • global_step (int) – Iteration associated with this value
  • walltime (float) – Wall clock time associated with this value
tag :str
labels :Union[torch.Tensor, numpy.array]
predictions :Union[torch.Tensor, numpy.array]
global_step :int
num_thresholds :int = 127
weights :Optional[float]
walltime :float
__repr__(self)
class flambe.logging.EmbeddingT[source]

Bases: typing.NamedTuple

Embedding data, including array of vaues and metadata

Supported by TensorboardX

Parameters:
  • mat (\((N, D)\)) – A matrix where each row is the feature vector of a data point
  • metadata (Sequence[str]) – A list of labels; each element will be converted to string
  • label_img (\((N, C, H, W)\)) – Images corresponding to each data point
  • global_step (int) – Iteration associated with this value
  • tag (str) – Data identifier
  • metadata_header (Sequence[str]) –
  • Shape
  • -----
  • mat – where N is number of data and D is feature dimension
  • label_img
mat :Union[torch.Tensor, numpy.array]
metadata :Sequence[str]
label_img :torch.Tensor
global_step :int
tag :str
metadata_header :Sequence[str]
__repr__(self)
class flambe.logging.GraphT[source]

Bases: typing.NamedTuple

PyTorch Model with input and other keyword args

Supported by ModelSave NOT YET Supported by TensorboardX

model

PyTorch Model (should have forward and state_dict methods)

Type:torch.nn.Module
input_to_model

Input to the model forward call

Type:torch.autograd.Variable
verbose

Include extra detail

Type:bool = False
kwargs

Other kwargs for model recording

Type:Dict[str, Any] = {}
model :torch.nn.Module
input_to_model :torch.autograd.Variable
verbose :bool = False
kwargs :Dict[str, Any]
flambe.logging.log(tag: str, data: ValueT, global_step: int, walltime: Optional[float] = None) → None[source]

Log data to tensorboard and console (convenience function)

Inspects type of data and uses the appropriate wrapper for tensorboard to consume the data. Supports floats (scalar), dictionary mapping tags to gloats (scalars), and strings (text).

Parameters:
  • tag (str) – Name of data, used as the tensorboard tag
  • data (ValueT) – The scalar or text to log
  • global_step (int) – Iteration number associated with data
  • walltime (Optional[float]) – Walltime for data (the default is None).

Examples

Normally you would have to do the following to log a scalar >>> import logging; from flambe.logging import ScalarT >>> logger = logging.getLogger(__name__) >>> logger.info(ScalarT(tag, data, step, walltime)) But this method allows you to write a more concise statement with a common interface >>> from flambe.logging import log >>> log(tag, data, step)

flambe.logging.coloredlogs[source]
flambe.logging.log_scalar(tag: str, data: float, global_step: int, walltime: Optional[float] = None, logger: Optional[logging.Logger] = None) → None[source]

Log tensorboard compatible scalar value with common interface

Parameters:
  • tag (str) – Tensorboard tag associated with scalar data
  • data (float) – Scalar float value
  • global_step (int) – The global step or iteration number
  • walltime (Optional[float]) – Current walltime, for example from time.time()
  • logger (Optional[logging.Logger]) – logger to use for logging the scalar
flambe.logging.log_scalars(tag: str, data: Dict[str, float], global_step: int, walltime: Optional[float] = None, logger: Optional[logging.Logger] = None) → None[source]

Log tensorboard compatible scalar values with common interface

Parameters:
  • tag (str) – Main tensorboard tag associated with all data
  • data (Dict[str, float]) – Scalar float value
  • global_step (int) – The global step or iteration number
  • walltime (Optional[float]) – Current walltime, for example from time.time()
  • logger (Optional[logging.Logger]) – logger to use for logging the scalar
flambe.logging.log_text(tag: str, data: str, global_step: int, walltime: Optional[float] = None, logger: Optional[logging.Logger] = None) → None[source]

Log tensorboard compatible text value with common interface

Parameters:
  • tag (str) – Tensorboard tag associated with data
  • data (str) – Scalar float value
  • global_step (int) – The global step or iteration number
  • walltime (Optional[float]) – Current walltime, for example from time.time()
  • logger (Optional[logging.Logger]) – logger to use for logging the scalar
flambe.logging.log_image(tag: str, data: str, global_step: int, walltime: Optional[float] = None, logger: Optional[logging.Logger] = None) → None[source]

Log tensorboard compatible image value with common interface

Parameters:
  • tag (str) – Tensorboard tag associated with data
  • data (str) – Scalar float value
  • global_step (int) – The global step or iteration number
  • walltime (Optional[float]) – Current walltime, for example from time.time()
  • logger (Optional[logging.Logger]) – logger to use for logging the scalar
flambe.logging.log_histogram(tag: str, data: str, global_step: int, bins: str = 'auto', walltime: Optional[float] = None, logger: Optional[logging.Logger] = None) → None[source]

Log tensorboard compatible image value with common interface

Parameters:
  • tag (str) – Tensorboard tag associated with data
  • data (str) – Scalar float value
  • global_step (int) – The global step or iteration number
  • walltime (Optional[float]) – Current walltime, for example from time.time()
  • logger (Optional[logging.Logger]) – logger to use for logging the scalar
flambe.logging.log_pr_curve(tag: str, labels: Union[torch.Tensor, numpy.array], predictions: Union[torch.Tensor, numpy.array], global_step: int, num_thresholds: int = 127, walltime: Optional[float] = None, logger: Optional[logging.Logger] = None) → None[source]

Log tensorboard compatible image value with common interface

Parameters:
  • tag (str) – Data identifier
  • labels (Union[torch.Tensor, numpy.array]) – Containing 0, 1 values
  • predictions (Union[torch.Tensor, numpy.array]) – Containing 0<=x<=1 values. Needs to match labels size
  • num_thresholds (int = 127) – The number of thresholds to evaluate. Max value allowed 127.
  • weights (Optional[float] = None) – No description provided.
  • global_step (int) – Iteration associated with this value
  • walltime (float) – Wall clock time associated with this value
  • logger (Optional[logging.Logger]) – logger to use for logging the scalar
flambe.logging.get_trial_dir() → str[source]

Get the output path used by the currently active trial.

Returns:The output path
Return type:str