跳到主要内容

使用 Logger - Jupyter Notebook

jupyter_logging_example.ipynb 脚本演示了 ClearML 显式报告模块 Logger 在 Jupyter Notebook 中的集成。所有 ClearML 显式报告都适用于 Jupyter Notebook。

此示例包含几种类型的显式报告,包括

  • 标量
  • 一些图表
  • 媒体。
注意

clearml GitHub 仓库中,此示例包含一个可点击的图标,可以在 Google Colab 中打开该 notebook。

标量

要报告标量,请调用 Logger.report_scalar()。标量图表出现在 Web UISCALARS 部分。

# report two scalar series on two different graphs
for i in range(10):
logger.report_scalar(title="graph A", series="series A", iteration=i, value=1./(i+1))
logger.report_scalar(title="graph B", series="series B", iteration=i, value=10./(i+1))

Separate scalar plots Separate scalar plots

# report two scalar series on the same graph
for i in range(10):
logger.report_scalar(title="unified graph", series="series A", iteration=i, value=1./(i+1))
logger.report_scalar(title="unified graph", series="series B", iteration=i, value=10./(i+1))

Unified scalar plots Unified scalar plots

图表

图表出现在 PLOTS 部分。

2D 图

通过调用 Logger.report_scatter2d() 报告 2D 散点图。使用 mode 参数将数据点绘制为标记,或同时绘制线条和标记。

scatter2d = np.hstack(
(np.atleast_2d(np.arange(0, 10)).T, np.random.randint(10, size=(10, 1)))
)
# report 2d scatter plot with markers
logger.report_scatter2d(
title="example_scatter",
series="series_lines+markers",
iteration=iteration,
scatter=scatter2d,
xaxis="title x",
yaxis="title y",
mode='lines+markers'
)

2d scatter plot 2d scatter plot

3D 图

要将系列绘制为 3D 散点图,请使用 Logger.report_scatter3d()

# report 3d scatter plot
scatter3d = np.random.randint(10, size=(10, 3))
logger.report_scatter3d(
title="example_scatter_3d",
series="series_xyz",
iteration=iteration,
scatter=scatter3d,
xaxis="title x",
yaxis="title y",
zaxis="title z",
)

3d scatter plot 3d scatter plot

要将系列绘制为曲面图,请使用 Logger.report_surface()

# report 3d surface
surface = np.random.randint(10, size=(10, 10))
logger.report_surface(
title="example_surface",
series="series1",
iteration=iteration,
matrix=surface,
xaxis="title X",
yaxis="title Y",
zaxis="title Z",
)

3d surface plot 3d surface plot

混淆矩阵

通过调用 Logger.report_confusion_matrix() 报告混淆矩阵。

# report confusion matrix
confusion = np.random.randint(10, size=(10, 10))
logger.report_confusion_matrix(
title="example_confusion",
series="ignored",
iteration=iteration,
matrix=confusion,
xaxis="title X",
yaxis="title Y",
)

Confusion matrix Confusion matrix

直方图

通过调用 Logger.report_histogram() 报告直方图。要在同一图表上报告多个系列,请使用相同的 title 参数。

# report a single histogram
histogram = np.random.randint(10, size=10)
logger.report_histogram(
title="single_histogram",
series="random histogram",
iteration=iteration,
values=histogram,
xaxis="title x",
yaxis="title y",
)

Histogram Histogram

# report a two histograms on the same plot
histogram1 = np.random.randint(13, size=10)
histogram2 = histogram * 0.75
logger.report_histogram(
title="two_histogram",
series="series 1",
iteration=iteration,
values=histogram1,
xaxis="title x",
yaxis="title y",
)
logger.report_histogram(
title="two_histogram",
series="series 2",
iteration=iteration,
values=histogram2,
xaxis="title x",
yaxis="title y",
)

Two histograms in one plot Two histograms in one plot

媒体

通过调用 Logger.report_media() 并使用 local_path 参数报告音频、HTML、图片和视频。它们出现在 DEBUG SAMPLES 中。

这些示例的媒体是使用 StorageManager.get_local_copy() 下载的。

例如,下载图片

image_local_copy = StorageManager.get_local_copy(
remote_url="https://pytorch.ac.cn/tutorials/_static/img/neural-style/picasso.jpg",
name="picasso.jpg"
)

音频

logger.report_media(title='audio', series='pink panther', iteration=1, local_path=audio_local_copy)

Audio sample Audio sample

HTML

logger.report_media(
title="html",
series="url_html",
iteration=1,
url="https://clearml.org.cn/docs/latest/docs/index.html"
)

HTML sample HTML sample

图片

logger.report_image(
title="image",
series="image from url",
iteration=100,
local_path=image_local_copy
)

Image sample Image sample

视频

logger.report_media(
title='video',
series='big bunny',
iteration=1,
local_path=video_local_copy
)

Video sample Video sample

文本

通过调用 Logger.report_text() 报告文本消息。

logger.report_text("hello, this is plain text")

Text report to console Text report to console