Shortcuts

pl_bolts.loggers package

Collection of PyTorchLightning loggers

class pl_bolts.loggers.TrainsLogger(project_name=None, task_name=None, task_type='training', reuse_last_task_id=True, output_uri=None, auto_connect_arg_parser=True, auto_connect_frameworks=True, auto_resource_monitoring=True)[source]

Bases: pytorch_lightning.loggers.base.LightningLoggerBase

Log using allegro.ai TRAINS. Install it with pip:

pip install trains

Example

>>> from pytorch_lightning import Trainer
>>> trains_logger = TrainsLogger(
...     project_name='pytorch lightning',
...     task_name='default',
...     output_uri='.',
... ) 
TRAINS Task: ...
TRAINS results page: ...
>>> trainer = Trainer(logger=trains_logger)

Use the logger anywhere in your LightningModule as follows:

>>> from pytorch_lightning import LightningModule
>>> class LitModel(LightningModule):
...     def training_step(self, batch, batch_idx):
...         # example
...         self.logger.experiment.whatever_trains_supports(...)
...
...     def any_lightning_module_function_or_hook(self):
...         self.logger.experiment.whatever_trains_supports(...)
Parameters
  • project_name (Optional[str]) – The name of the experiment’s project. Defaults to None.

  • task_name (Optional[str]) – The name of the experiment. Defaults to None.

  • task_type (str) – The name of the experiment. Defaults to 'training'.

  • reuse_last_task_id (bool) – Start with the previously used task id. Defaults to True.

  • output_uri (Optional[str]) – Default location for output models. Defaults to None.

  • auto_connect_arg_parser (bool) – Automatically grab the ArgumentParser and connect it with the task. Defaults to True.

  • auto_connect_frameworks (bool) – If True, automatically patch to trains backend. Defaults to True.

  • auto_resource_monitoring (bool) – If True, machine vitals will be sent along side the task scalars. Defaults to True.

Examples

>>> logger = TrainsLogger("pytorch lightning", "default", output_uri=".")  
TRAINS Task: ...
TRAINS results page: ...
>>> logger.log_metrics({"val_loss": 1.23}, step=0)
>>> logger.log_text("sample test")
sample test
>>> import numpy as np
>>> logger.log_artifact("confusion matrix", np.ones((2, 3)))
>>> logger.log_image("passed", "Image 1", np.random.randint(0, 255, (200, 150, 3), dtype=np.uint8))
classmethod bypass_mode()[source]

Returns the bypass mode state.

Note

GITHUB_ACTIONS env will automatically set bypass_mode to True unless overridden specifically with TrainsLogger.set_bypass_mode(False).

Return type

bool

Returns

If True, all outside communication is skipped.

finalize(status=None)[source]
Return type

None

log_artifact(name, artifact, metadata=None, delete_after_upload=False)[source]

Save an artifact (file/object) in TRAINS experiment storage.

Parameters
  • name (str) – Artifact name. Notice! it will override the previous artifact if the name already exists.

  • artifact (Union[str, Path, Dict[str, Any], ndarray, Image]) –

    Artifact object to upload. Currently supports:

    • string / pathlib.Path are treated as path to artifact file to upload If a wildcard or a folder is passed, a zip file containing the local files will be created and uploaded.

    • dict will be stored as .json file and uploaded

    • pandas.DataFrame will be stored as .csv.gz (compressed CSV file) and uploaded

    • numpy.ndarray will be stored as .npz and uploaded

    • PIL.Image.Image will be stored to .png file and uploaded

  • metadata (Optional[Dict[str, Any]]) – Simple key/value dictionary to store on the artifact. Defaults to None.

  • delete_after_upload (bool) – If True, the local artifact will be deleted (only applies if artifact is a local file). Defaults to False.

Return type

None

log_hyperparams(params)[source]

Log hyperparameters (numeric values) in TRAINS experiments.

Parameters

params (Union[Dict[str, Any], Namespace]) – The hyperparameters that passed through the model.

Return type

None

log_image(title, series, image, step=None)[source]

Log Debug image in TRAINS experiment

Parameters
  • title (str) – The title of the debug image, i.e. “failed”, “passed”.

  • series (str) – The series name of the debug image, i.e. “Image 0”, “Image 1”.

  • image (Union[str, ndarray, Image, Tensor]) –

    Debug image to log. If numpy.ndarray or torch.Tensor, the image is assumed to be the following:

    • shape: CHW

    • color space: RGB

    • value range: [0., 1.] (float) or [0, 255] (uint8)

  • step (Optional[int]) – Step number at which the metrics should be recorded. Defaults to None.

Return type

None

log_metric(title, series, value, step=None)[source]

Log metrics (numeric values) in TRAINS experiments. This method will be called by the users.

Parameters
  • title (str) – The title of the graph to log, e.g. loss, accuracy.

  • series (str) – The series name in the graph, e.g. classification, localization.

  • value (float) – The value to log.

  • step (Optional[int]) – Step number at which the metrics should be recorded. Defaults to None.

Return type

None

log_metrics(metrics, step=None)[source]

Log metrics (numeric values) in TRAINS experiments. This method will be called by Trainer.

Parameters
  • metrics (Dict[str, float]) – The dictionary of the metrics. If the key contains “/”, it will be split by the delimiter, then the elements will be logged as “title” and “series” respectively.

  • step (Optional[int]) – Step number at which the metrics should be recorded. Defaults to None.

Return type

None

log_text(text)[source]

Log console text data in TRAINS experiment.

Parameters

text (str) – The value of the log (data-point).

Return type

None

classmethod set_bypass_mode(bypass)[source]

Will bypass all outside communication, and will drop all logs. Should only be used in “standalone mode”, when there is no access to the trains-server.

Parameters

bypass (bool) – If True, all outside communication is skipped.

Return type

None

classmethod set_credentials(api_host=None, web_host=None, files_host=None, key=None, secret=None)[source]

Set new default TRAINS-server host and credentials. These configurations could be overridden by either OS environment variables or trains.conf configuration file.

Note

Credentials need to be set prior to Logger initialization.

Parameters
  • api_host (Optional[str]) – Trains API server url, example: host='http://localhost:8008'

  • web_host (Optional[str]) – Trains WEB server url, example: host='http://localhost:8080'

  • files_host (Optional[str]) – Trains Files server url, example: host='http://localhost:8081'

  • key (Optional[str]) – user key/secret pair, example: key='thisisakey123'

  • secret (Optional[str]) – user key/secret pair, example: secret='thisisseceret123'

Return type

None

_bypass = None[source]
property experiment[source]

Actual TRAINS object. To use TRAINS features in your LightningModule do the following.

Example:

self.logger.experiment.some_trains_function()
Return type

Task

property id[source]

ID is a uuid (string) representing this specific experiment in the entire system.

Return type

Optional[str]

property name[source]

Name is a human readable non-unique name (str) of the experiment.

Return type

Optional[str]

property version[source]
Return type

Optional[str]

Read the Docs v: 0.2.0
Versions
latest
stable
0.2.0
0.1.1
0.1.0
Downloads
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.