Skip to main content

Logger

class Logger()#

The Logger class is the ClearML console log and metric statistics interface, and contains methods for explicit reporting.

Explicit reporting extends ClearML automagical capturing of inputs and output. Explicit reporting methods include scalar plots, line plots, histograms, confusion matrices, 2D and 3D scatter diagrams, text logging, tables, and image uploading and reporting.

In the ClearML Web-App (UI), Logger output appears in the RESULTS tab, CONSOLE, SCALARS, PLOTS, and DEBUG SAMPLES sub-tabs. When you compare experiments, Logger output appears in the comparisons.

warning

Do not construct Logger objects directly.

You must get a Logger object before calling any of the other Logger class methods by calling Task.get_logger or Logger.current_logger.

warning

Do not construct Logger manually! Please use Logger.get_current


Logger.current_logger#

classmethod current_logger()

Get the Logger object for the main execution Task, the current running Task, if one exists. If no Logger object exists, this method creates one and returns it. Therefore, you can call this method from anywhere in the code.

logger = Logger.current_logger()
  • Return type

    Logger

  • Returns

    The Logger object (a singleton) for the current running Task.


report_text#

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

For explicit reporting, print text to the log. Optionally, print a log level and print to the console.

For example:

logger.report_text('log some text', level=logging.DEBUG, print_console=False)

You can view the reported text in the ClearML Web-App (UI), RESULTS tab, CONSOLE sub-tab.

  • Parameters

    • msg (str ) – The text to log.

    • level (int ) – The log level from the Python logging package. The default value is logging.INFO.

    • print_console (bool ) – In addition to the log, print to the console

      The values are:

      * `True` - Print to the console. (default)
      * `False` - Do not print to the console.
    • args (Any ) –

    • _ (Any ) –

  • Return type

    None


report_scalar#

report_scalar(title, series, value, iteration)

For explicit reporting, plot a scalar series.

For example, plot a scalar series:

scalar_series = [random.randint(0,10) for i in range(10)]
logger.report_scalar(title='scalar metrics','series', value=scalar_series[iteration], iteration=0)

You can view the scalar plots in the ClearML Web-App (UI), RESULTS tab, SCALARS sub-tab.

  • Parameters

    • title (str ) – The title (metric) of the plot. Plot more than one scalar series on the same plot by using the same title for each call to this method.

    • series (str ) – The series name (variant) of the reported scalar.

    • value (float ) – The value to plot per iteration.

    • iteration (int ) – The reported iteration / step (x-axis of the reported time series)

  • Return type

    None


report_vector#

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

For explicit reporting, plot a vector as (default stacked) histogram.

For example:

vector_series = np.random.randint(10, size=10).reshape(2,5)
logger.report_vector(title='vector example', series='vector series', values=vector_series, iteration=0,
labels=['A','B'], xaxis='X axis label', yaxis='Y axis label')

You can view the vectors plots in the ClearML Web-App (UI), RESULTS tab, PLOTS sub-tab.

  • Parameters

    • title – The title (metric) of the plot.

    • series – The series name (variant) of the reported histogram.

    • values – The series values. A list of floats, or an N-dimensional Numpy array containing data for each histogram bar.

    • iteration – The reported iteration / step. Each iteration creates another plot.

    • labels – Labels for each bar group, creating a plot legend labeling each series. (Optional)

    • xlabels – Labels per entry in each bucket in the histogram (vector), creating a set of labels for each histogram bar on the x-axis. (Optional)

    • xaxis – The x-axis title. (Optional)

    • yaxis – The y-axis title. (Optional)

    • mode – Multiple histograms mode, stack / group / relative. Default is β€˜group’.

    • extra_layout – optional dictionary for layout configuration, passed directly to plotly example: extra_layout={β€˜xaxis’: {β€˜type’: β€˜date’, β€˜range’: [β€˜2020-01-01’, β€˜2020-01-31’]}}


report_histogram#

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

For explicit reporting, plot a (default grouped) histogram. Notice this function will not calculate the histogram, it assumes the histogram was already calculated in values

For example:

vector_series = np.random.randint(10, size=10).reshape(2,5)
logger.report_histogram(title='histogram example', series='histogram series',
values=vector_series, iteration=0, labels=['A','B'], xaxis='X axis label', yaxis='Y axis label')

You can view the reported histograms in the ClearML Web-App (UI), RESULTS tab, PLOTS sub-tab.

  • Parameters

    • title – The title (metric) of the plot.

    • series – The series name (variant) of the reported histogram.

    • values – The series values. A list of floats, or an N-dimensional Numpy array containing data for each histogram bar.

    • iteration – The reported iteration / step. Each iteration creates another plot.

    • labels – Labels for each bar group, creating a plot legend labeling each series. (Optional)

    • xlabels – Labels per entry in each bucket in the histogram (vector), creating a set of labels for each histogram bar on the x-axis. (Optional)

    • xaxis – The x-axis title. (Optional)

    • yaxis – The y-axis title. (Optional)

    • mode – Multiple histograms mode, stack / group / relative. Default is β€˜group’.

    • extra_layout – optional dictionary for layout configuration, passed directly to plotly example: extra_layout={β€˜xaxis’: {β€˜type’: β€˜date’, β€˜range’: [β€˜2020-01-01’, β€˜2020-01-31’]}}


report_table#

report_table(title, series, iteration=None, table_plot=None, csv=None, url=None, extra_layout=None)

For explicit report, report a table plot.

One and only one of the following parameters must be provided.

  • table_plot - Pandas DataFrame or Table as list of rows (list)

  • csv - CSV file

  • url - URL to CSV file

For example:

df = pd.DataFrame({'num_legs': [2, 4, 8, 0],
'num_wings': [2, 0, 0, 0],
'num_specimen_seen': [10, 2, 1, 8]},
index=['falcon', 'dog', 'spider', 'fish'])
logger.report_table(title='table example',series='pandas DataFrame',iteration=0,table_plot=df)

You can view the reported tables in the ClearML Web-App (UI), RESULTS tab, PLOTS sub-tab.

  • Parameters

    • title – The title (metric) of the table.

    • series – The series name (variant) of the reported table.

    • iteration – The reported iteration / step.

    • table_plot – The output table plot object

    • csv – path to local csv file

    • url – A URL to the location of csv file.

    • extra_layout – optional dictionary for layout configuration, passed directly to plotly example: extra_layout={β€˜xaxis’: {β€˜type’: β€˜date’, β€˜range’: [β€˜2020-01-01’, β€˜2020-01-31’]}}


report_line_plot#

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

For explicit reporting, plot one or more series as lines.

  • Parameters

    • title (str ) – The title (metric) of the plot.

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

    • iteration (int ) – The reported iteration / step.

    • xaxis (str ) – The x-axis title. (Optional)

    • yaxis (str ) – The y-axis title. (Optional)

    • mode (str ) – The type of line plot.

      The values are:

      * `lines` (default)
      * `markers`
      * `lines+markers`
    • reverse_xaxis (bool ) – Reverse the x-axis

      The values are:

      * `True` - The x-axis is high to low (reversed).
      * `False` - The x-axis is low to high (not reversed). (default)
    • comment (str ) – A comment displayed with the plot, underneath the title.

    • extra_layout (dict ) – optional dictionary for layout configuration, passed directly to plotly example: extra_layout={β€˜xaxis’: {β€˜type’: β€˜date’, β€˜range’: [β€˜2020-01-01’, β€˜2020-01-31’]}}


report_scatter2d#

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

For explicit reporting, report a 2d scatter plot.

For example:

scatter2d = np.hstack((np.atleast_2d(np.arange(0, 10)).T, np.random.randint(10, size=(10, 1))))
logger.report_scatter2d(title="example_scatter", series="series", iteration=0, scatter=scatter2d,
xaxis="title x", yaxis="title y")

Plot multiple 2D scatter series on the same plot by passing the same title and iteration values to this method:

scatter2d_1 = np.hstack((np.atleast_2d(np.arange(0, 10)).T, np.random.randint(10, size=(10, 1))))
logger.report_scatter2d(title="example_scatter", series="series_1", iteration=1, scatter=scatter2d_1,
xaxis="title x", yaxis="title y")
scatter2d_2 = np.hstack((np.atleast_2d(np.arange(0, 10)).T, np.random.randint(10, size=(10, 1))))
logger.report_scatter2d("example_scatter", "series_2", iteration=1, scatter=scatter2d_2,
xaxis="title x", yaxis="title y")
  • Parameters

    • title (str ) – The title (metric) of the plot.

    • series (str ) – The series name (variant) of the reported scatter plot.

    • scatter (list ) – The scatter data. numpy.ndarray or list of (pairs of x,y) scatter:

    • iteration (int ) – The reported iteration / step.

    • xaxis (str ) – The x-axis title. (Optional)

    • yaxis (str ) – The y-axis title. (Optional)

    • labels (list ( str ) ) – Labels per point in the data assigned to the scatter parameter. The labels must be in the same order as the data.

    • mode (str ) – The type of scatter plot.

      The values are:

      * `lines`
      * `markers`
      * `lines+markers`
    • comment (str ) – A comment displayed with the plot, underneath the title.

    • extra_layout (dict ) – optional dictionary for layout configuration, passed directly to plotly example: extra_layout={β€˜xaxis’: {β€˜type’: β€˜date’, β€˜range’: [β€˜2020-01-01’, β€˜2020-01-31’]}}


report_scatter3d#

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

For explicit reporting, plot a 3d scatter graph (with markers).

  • Parameters

    • title (str ) – The title (metric) of the plot.

    • series (str ) – The series name (variant) of the reported scatter plot.

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

    • iteration (int ) – The reported iteration / step.

    • xaxis (str ) – The x-axis title. (Optional)

    • yaxis (str ) – The y-axis title. (Optional)

    • zaxis (str ) – The z-axis title. (Optional)

    • labels (list ( str ) ) – Labels per point in the data assigned to the scatter parameter. The labels must be in the same order as the data.

    • mode (str ) – The type of scatter plot.

      The values are:

      * `lines`
      * `markers`
      * `lines+markers`

For example:

scatter3d = np.random.randint(10, size=(10, 3))
logger.report_scatter3d(title="example_scatter_3d", series="series_xyz", iteration=1, scatter=scatter3d,
xaxis="title x", yaxis="title y", zaxis="title z")
  • Parameters

    • fill (bool ) – Fill the area under the curve

      The values are:

      * `True` - Fill
      * `False` - Do not fill (default)
    • comment (str ) – A comment displayed with the plot, underneath the title.

    • extra_layout (dict ) – optional dictionary for layout configuration, passed directly to plotly example: extra_layout={β€˜xaxis’: {β€˜type’: β€˜date’, β€˜range’: [β€˜2020-01-01’, β€˜2020-01-31’]}}


report_confusion_matrix#

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

For explicit reporting, plot a heat-map matrix.

For example:

confusion = np.random.randint(10, size=(10, 10))
logger.report_confusion_matrix("example confusion matrix", "ignored", iteration=1, matrix=confusion,
xaxis="title X", yaxis="title Y")
  • Parameters

    • title (str ) – The title (metric) of the plot.

    • series (str ) – The series name (variant) of the reported confusion matrix.

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

    • iteration (int ) – The reported iteration / step.

    • xaxis (str ) – The x-axis title. (Optional)

    • yaxis (str ) – The y-axis title. (Optional)

    • xlabels (list ( str ) ) – Labels for each column of the matrix. (Optional)

    • ylabels (list ( str ) ) – Labels for each row of the matrix. (Optional)

    • yaxis_reversed (bool ) – If False 0,0 is at the bottom left corner. If True 0,0 is at the Top left corner

    • comment (str ) – A comment displayed with the plot, underneath the title.

    • extra_layout (dict ) – optional dictionary for layout configuration, passed directly to plotly example: extra_layout={β€˜xaxis’: {β€˜type’: β€˜date’, β€˜range’: [β€˜2020-01-01’, β€˜2020-01-31’]}}


report_matrix#

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

For explicit reporting, plot a confusion matrix.

info

This method is the same as Logger.report_confusion_matrix.

  • Parameters

    • title (str ) – The title (metric) of the plot.

    • series (str ) – The series name (variant) of the reported confusion matrix.

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

    • iteration (int ) – The reported iteration / step.

    • xaxis (str ) – The x-axis title. (Optional)

    • yaxis (str ) – The y-axis title. (Optional)

    • xlabels (list ( str ) ) – Labels for each column of the matrix. (Optional)

    • ylabels (list ( str ) ) – Labels for each row of the matrix. (Optional)

    • yaxis_reversed (bool ) – If False 0,0 is at the bottom left corner. If True 0,0 is at the Top left corner

    • extra_layout (dict ) – optional dictionary for layout configuration, passed directly to plotly example: extra_layout={β€˜xaxis’: {β€˜type’: β€˜date’, β€˜range’: [β€˜2020-01-01’, β€˜2020-01-31’]}}


report_surface#

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

For explicit reporting, report a 3d surface plot.

info

This method plots the same data as Logger.report_confusion_matrix, but presents the data as a surface diagram not a confusion matrix.

surface_matrix = np.random.randint(10, size=(10, 10))
logger.report_surface("example surface", "series", iteration=0, matrix=surface_matrix,
xaxis="title X", yaxis="title Y", zaxis="title Z")
  • Parameters

    • title (str ) – The title (metric) of the plot.

    • series (str ) – The series name (variant) of the reported surface.

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

    • iteration (int ) – The reported iteration / step.

    • xaxis (str ) – The x-axis title. (Optional)

    • yaxis (str ) – The y-axis title. (Optional)

    • zaxis (str ) – The z-axis title. (Optional)

    • xlabels (list ( str ) ) – Labels for each column of the matrix. (Optional)

    • ylabels (list ( str ) ) – Labels for each row of the matrix. (Optional)

    • camera (list ( float ) ) – X,Y,Z coordinates indicating the camera position. The default value is (1,1,1).

    • comment (str ) – A comment displayed with the plot, underneath the title.

    • extra_layout (dict ) – optional dictionary for layout configuration, passed directly to plotly example: extra_layout={β€˜xaxis’: {β€˜type’: β€˜date’, β€˜range’: [β€˜2020-01-01’, β€˜2020-01-31’]}}


report_image#

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

For explicit reporting, report an image and upload its contents.

This method uploads the image to a preconfigured bucket (see Logger.set_default_upload_destination) describing the task ID, title, series and iteration.

For example:

matrix = np.eye(256, 256, dtype=np.uint8)*255
matrix = np.concatenate((np.atleast_3d(matrix), np.zeros((256, 256, 2), dtype=np.uint8)), axis=2)
logger.report_image("test case", "image color red", iteration=1, image=m)
image_open = Image.open(os.path.join("<image_path>", "<image_filename>"))
logger.report_image("test case", "image PIL", iteration=1, image=image_open)

One and only one of the following parameters must be provided.

  • local_path

  • url

  • image

  • matrix

  • Parameters

    • title – The title (metric) of the image.

    • series – The series name (variant) of the reported image.

    • iteration – The reported iteration / step.

    • local_path – A path to an image file.

    • url – A URL for the location of a pre-uploaded image.

    • image – Image data (RGB).

    • matrix – Deperacted, Image data (RGB).

      info

      The matrix parameter is deprecated. Use the image parameters.

    • max_image_history – The maximum number of images to store per metric/variant combination. For an unlimited number, use a negative value. The default value is set in global configuration (default=``5``).

    • delete_after_upload – After the upload, delete the local copy of the image

      The values are:

      * `True` - Delete after upload.
      * `False` - Do not delete after upload. (default)

report_media#

report_media(title, series, iteration=None, local_path=None, stream=None, file_extension=None, max_history=None, delete_after_upload=False, url=None)

Report media upload its contents, including images, audio, and video.

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

One and only one of the following parameters must be provided

  • local_path

  • stream

  • url

If you use stream for a BytesIO stream to upload, file_extension must be provided.

  • Parameters

    • title (str ) – The title (metric) of the media.

    • series (str ) – The series name (variant) of the reported media.

    • iteration (int ) – The reported iteration / step.

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

    • stream – BytesIO stream to upload. If provided, file_extension must also be provided.

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

    • file_extension – A file extension to use when stream is passed.

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

    • delete_after_upload (bool ) – After the file is uploaded, delete the local copy

      • True - Delete

      • False - Do not delete


report_plotly#

report_plotly(title, series, figure, iteration=None)

Report a Plotly figure (plot) directly

Plotly figure can be a plotly.graph_objs._figure.Figure or a dictionary as defined by plotly.js

  • Parameters

    • title (str ) – The title (metric) of the plot.

    • series (str ) – The series name (variant) of the reported plot.

    • iteration (int ) – The reported iteration / step.

    • figure (dict ) – A plotly Figure object or a poltly dictionary


report_matplotlib_figure#

report_matplotlib_figure(title, series, figure, iteration=None, report_image=False, report_interactive=True)

Report a matplotlib figure / plot directly

matplotlib.figure.Figure / matplotlib.pyplot

  • Parameters

    • title (str ) – The title (metric) of the plot.

    • series (str ) – The series name (variant) of the reported plot.

    • iteration (int ) – The reported iteration / step.

    • figure (MatplotlibFigure ) – A matplotlib Figure object

    • report_image – Default False. If True the plot will be uploaded as a debug sample (png image), and will appear under the debug samples tab (instead of the Plots tab).

    • report_interactive – If True (default) it will try to convert the matplotlib into interactive plot in the UI. If False the matplotlib is saved as is and will be non-interactive (with the exception of zooming in/out)


set_default_upload_destination#

set_default_upload_destination(uri)

Set the destination storage URI (for example, S3, Google Cloud Storage, a file path) for uploading debug images.

The images are uploaded separately. A link to each image is reported.

info

Credentials for the destination storage are specified in the ClearML configuration file, ~/clearml.conf.

  • Parameters

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

  • Return type

    None

  • Returns

    True, if the destination scheme is supported (for example, s3://, file://, or gc://). False, if not supported.


get_default_upload_destination#

get_default_upload_destination()

Get the destination storage URI (for example, S3, Google Cloud Storage, a file path) for uploading debug images (see Logger.set_default_upload_destination).

  • Return type

    str

  • Returns

    The default upload destination URI.

    For example: s3://bucket/directory/, or file:///tmp/debug/.


flush#

flush(wait=False)

Flush cached reports and console outputs to backend.

  • Parameters

    wait (bool) – Wait for all outstanding uploads and events to be sent (default False)

  • Return type

    bool

  • Returns

    True, if successfully flushed the cache. False, if failed.


get_flush_period#

get_flush_period()

Get the Logger flush period.

  • Return type

    Optional[float]

  • Returns

    The logger flush period in seconds.


set_flush_period#

set_flush_period(period)

Set the logger flush period.

Deprecated - Use sdk.development.worker.report_period_sec to externally control the flush period.

  • Parameters

    period (float ) – The period to flush the logger in seconds. To set no periodic flush, specify None or 0.

  • Return type

    None


report_image_and_upload#

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

Deprecated: Deprecated since version 0.13.0: Use Logger.report_image instead


capture_logging#

capture_logging()

Return context capturing all the logs (via logging) reported under the context

  • Return type

    ForwardRef

  • Returns

    a ContextManager


Logger.tensorboard_auto_group_scalars#

classmethod tensorboard_auto_group_scalars(group_scalars=False)

Group together TensorBoard scalars that do not have a title, or assign a title/series with the same tag.

  • Parameters

    group_scalars (bool) – Group TensorBoard scalars without a title

    The values are:

    • True - Scalars without specific titles are grouped together in the β€œScalars” plot, preserving backward compatibility with ClearML automagical behavior.

    • False - TensorBoard scalars without titles get a title/series with the same tag. (default)

  • Return type

    None


Logger.tensorboard_single_series_per_graph#

classmethod tensorboard_single_series_per_graph(single_series=False)

Deprecated, this is now controlled from the UI! Group TensorBoard scalar series together or in separate plots.

  • Parameters

    single_series (bool) – Group TensorBoard scalar series together

    The values are:

    • True - Generate a separate plot for each TensorBoard scalar series.

    • False - Group the TensorBoard scalar series together in the same plot. (default)

  • Return type

    None


Logger.matplotlib_force_report_non_interactive#

classmethod matplotlib_force_report_non_interactive(force)

If True all matplotlib are always converted to non interactive static plots (images), appearing in under the Plots section. If False (default), matplotlib figures are converted into interactive web UI plotly figures, in case figure conversion fails, it defaults to non-interactive plots.

  • Parameters

    force (bool) – If True all matplotlib figures are converted automatically to non-interactive plots.

  • Return type

    None