pytorch_lightning.loggers.trains module¶
TRAINS¶
-
class
pytorch_lightning.loggers.trains.
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 >>> from pytorch_lightning.loggers import TrainsLogger >>> 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 toNone
.task_name¶ (
Optional
[str
]) – The name of the experiment. Defaults toNone
.task_type¶ (
str
) – The name of the experiment. Defaults to'training'
.reuse_last_task_id¶ (
bool
) – Start with the previously used task id. Defaults toTrue
.output_uri¶ (
Optional
[str
]) – Default location for output models. Defaults toNone
.auto_connect_arg_parser¶ (
bool
) – Automatically grab theArgumentParser
and connect it with the task. Defaults toTrue
.auto_connect_frameworks¶ (
bool
) – IfTrue
, automatically patch to trains backend. Defaults toTrue
.auto_resource_monitoring¶ (
bool
) – IfTrue
, machine vitals will be sent along side the task scalars. Defaults toTrue
.
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 withTrainsLogger.set_bypass_mode(False)
.- Return type
- Returns
If True, all outside communication is skipped.
-
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 uploadednumpy.ndarray
will be stored as .npz and uploadedPIL.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 toNone
.delete_after_upload¶ (
bool
) – IfTrue
, the local artifact will be deleted (only applies ifartifact
is a local file). Defaults toFalse
.
- 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
ortorch.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
- Return type
None
-
log_metrics
(metrics, step=None)[source]¶ Log metrics (numeric values) in TRAINS experiments. This method will be called by Trainer.
- Parameters
- 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.
-
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
-
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.