trains.logger

class trains.logger.Logger(private_task)

Console log and metric statistics interface.

This is how we send graphs/plots/text to the system, later we can compare the performance of different tasks.

Usage: Logger.current_logger() or Task.get_logger()

Do not construct Logger manually!

please use Logger.current_logger()

classmethod current_logger()

Return a logger object for the current task. Can be called from anywhere in the code

Returns

Singleton Logger object for the current running task

report_text(msg, level=20, print_console=True, *args, **_)

print text to log and optionally also prints to console

Parameters
  • msg (str) – text to print to the console (always send to the backend and displayed in console)

  • level (int) – logging level, default: logging.INFO

  • print_console (bool) – If True we also print ‘msg’ to console

report_scalar(title, series, value, iteration)

Report a scalar value

Parameters
  • title (str) – Title (AKA metric)

  • series (str) – Series (AKA variant)

  • value (float) – Reported value

  • iteration (int) – Iteration number

report_vector(title, series, values, iteration, labels=None, xlabels=None, xaxis=None, yaxis=None)

Report a histogram plot

Parameters
  • title (str) – Title (AKA metric)

  • series (str) – Series (AKA variant)

  • values (list(float)) – Reported values (or numpy array)

  • iteration (int) – Iteration number

  • labels (list(str)) – optional, labels for each bar group.

  • xlabels (list(str)) – optional label per entry in the vector (bucket in the histogram)

  • xaxis (str) – optional x-axis title

  • yaxis (str) – optional y-axis title

report_histogram(title, series, values, iteration, labels=None, xlabels=None, xaxis=None, yaxis=None)

Report a histogram plot

Parameters
  • title (str) – Title (AKA metric)

  • series (str) – Series (AKA variant)

  • values (list(float)) – Reported values (or numpy array)

  • iteration (int) – Iteration number

  • labels (list(str)) – optional, labels for each bar group.

  • xlabels (list(str)) – optional label per entry in the vector (bucket in the histogram)

  • xaxis (str) – optional x-axis title

  • yaxis (str) – optional y-axis title

report_line_plot(title, series, iteration, xaxis, yaxis, mode='lines', reverse_xaxis=False, comment=None)

Report a (possibly multiple) line plot.

Parameters
  • title (str) – Title (AKA metric)

  • series (list(LineSeriesInfo)) – All the series’ data, one for each line in the plot.

  • iteration (int) – Iteration number

  • xaxis (str) – optional x-axis title

  • yaxis (str) – optional y-axis title

  • mode (str) – scatter plot with ‘lines’/’markers’/’lines+markers’

  • reverse_xaxis (bool) – If true X axis will be displayed from high to low (reversed)

  • comment (str) – comment underneath the title

report_scatter2d(title, series, scatter, iteration, xaxis=None, yaxis=None, labels=None, mode='lines', comment=None)

Report a 2d scatter graph (with lines)

Parameters
  • title (str) – Title (AKA metric)

  • series (str) – Series (AKA variant)

  • scatter (np.ndarray) – A scattered data: list of (pairs of x,y) (or numpy array)

  • iteration (int) – Iteration number

  • xaxis (str) – optional x-axis title

  • yaxis (str) – optional y-axis title

  • labels (list(str)) – label (text) per point in the scatter (in the same order)

  • mode (str) – scatter plot with ‘lines’/’markers’/’lines+markers’

  • comment (str) – comment underneath the title

report_scatter3d(title, series, scatter, iteration, xaxis=None, yaxis=None, zaxis=None, labels=None, mode='markers', fill=False, comment=None)

Report a 3d scatter graph (with markers)

Parameters
  • title (str) – Title (AKA metric)

  • series (str) – Series (AKA variant)

  • list] scatter (Union[np.ndarray,) – A scattered data: list of (pairs of x,y,z) (or numpy array) or list of series [[(x1,y1,z1)…]]

  • iteration (int) – Iteration number

  • xaxis (str) – optional x-axis title

  • yaxis (str) – optional y-axis title

  • zaxis (str) – optional z-axis title

  • labels (list(str)) – label (text) per point in the scatter (in the same order)

  • mode (str) – scatter plot with ‘lines’/’markers’/’lines+markers’

  • fill (bool) – fill area under the curve

  • comment (str) – comment underneath the title

report_confusion_matrix(title, series, matrix, iteration, xaxis=None, yaxis=None, xlabels=None, ylabels=None, comment=None)

Report a heat-map matrix

Parameters
  • title (str) – Title (AKA metric)

  • series (str) – Series (AKA variant)

  • matrix (np.ndarray) – A heat-map matrix (example: confusion matrix)

  • iteration (int) – Iteration number

  • xaxis (str) – optional x-axis title

  • yaxis (str) – optional y-axis title

  • xlabels (list(str)) – optional label per column of the matrix

  • ylabels (list(str)) – optional label per row of the matrix

  • comment (str) – comment underneath the title

report_matrix(title, series, matrix, iteration, xaxis=None, yaxis=None, xlabels=None, ylabels=None)

Same as report_confusion_matrix Report a heat-map matrix

Parameters
  • title (str) – Title (AKA metric)

  • series (str) – Series (AKA variant)

  • matrix (np.ndarray) – A heat-map matrix (example: confusion matrix)

  • iteration (int) – Iteration number

  • xaxis (str) – optional x-axis title

  • yaxis (str) – optional y-axis title

  • xlabels (list(str)) – optional label per column of the matrix

  • ylabels (list(str)) – optional label per row of the matrix

report_surface(title, series, matrix, iteration, xaxis=None, yaxis=None, zaxis=None, xlabels=None, ylabels=None, camera=None, comment=None)

Report a 3d surface (same data as heat-map matrix, only presented differently)

Parameters
  • title (str) – Title (AKA metric)

  • series (str) – Series (AKA variant)

  • matrix (np.ndarray) – A heat-map matrix (example: confusion matrix)

  • iteration (int) – Iteration number

  • xaxis (str) – optional x-axis title

  • yaxis (str) – optional y-axis title

  • zaxis (str) – optional z-axis title

  • xlabels (list(str)) – optional label per column of the matrix

  • ylabels (list(str)) – optional label per row of the matrix

  • camera (list(float)) – X,Y,Z camera position. def: (1,1,1)

  • comment (str) – comment underneath the title

report_image(title, series, iteration, local_path=None, image=None, matrix=None, max_image_history=None, delete_after_upload=False, url=None)

Report an image and upload its contents.

Image is uploaded to a preconfigured bucket (see setup_upload()) with a key (filename) describing the task ID, title, series and iteration.

Note

local_path, url, image and matrix are mutually exclusive, and at least one must be provided.

Parameters
  • title (str) – Title (AKA metric)

  • series (str) – Series (AKA variant)

  • iteration (int) – Iteration number

  • local_path (str) – A path to an image file.

  • url (str) – A URL to the location of a pre-uploaded image.

  • Image image (np.ndarray) – Could be a PIL.Image.Image object or a 3D numpy.ndarray object containing image data (RGB).

  • matrix (np.ndarray) – A 3D numpy.ndarray object containing image data (RGB). This is deprecated, use image variable instead.

  • max_image_history (int) – maximum number of image to store per metric/variant combination use negative value for unlimited. default is set in global configuration (default=5)

  • delete_after_upload (bool) – if True, one the file was uploaded the local copy will be deleted

set_default_upload_destination(uri)

Set the uri to upload all the debug images to.

Images are uploaded separately to the destination storage (e.g. s3,gc,file) and then a link to the uploaded image is sent in the report Notice: credentials for the upload destination will be pooled from the global configuration file (i.e. ~/trains.conf)

Parameters

uri (str) – example: ‘s3://bucket/directory/’ or ‘file:///tmp/debug/’

Returns

True if destination scheme is supported (i.e. s3:// file:// gc:// etc…)

get_default_upload_destination()

Get the uri to upload all the debug images to.

Images are uploaded separately to the destination storage (e.g. s3,gc,file) and then a link to the uploaded image is sent in the report Notice: credentials for the upload destination will be pooled from the global configuration file (i.e. ~/trains.conf)

Returns

Uri (str) example: ‘s3://bucket/directory/’ or ‘file:///tmp/debug/’ etc…

flush()

Flush cached reports and console outputs to backend.

Returns

True if successful

get_flush_period()
Returns

logger flush period in seconds

set_flush_period(period)

Set the period of the logger flush.

Parameters

period (float) – The period to flush the logger in seconds. If None or 0, There will be no periodic flush.

report_image_and_upload(title, series, iteration, path=None, matrix=None, max_image_history=None, delete_after_upload=False)

Deprecated: Backwards compatibility, please use report_image instead

classmethod tensorboard_auto_group_scalars(group_scalars=False)

If group_scalars set to True, we preserve backward compatible Tensorboard auto-magic behaviour, i.e. Scalars without specific title will be grouped under the “Scalars” graph. Default is False: Tensorboard scalars without title will have title/series with the same tag