2021-05-13 23:48:51 +00:00
|
|
|
---
|
2021-12-22 08:54:04 +00:00
|
|
|
title: Using Logger - Jupyter Notebook
|
2021-05-13 23:48:51 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
The [jupyter_logging_example.ipynb](https://github.com/allegroai/clearml/blob/master/examples/reporting/jupyter_logging_example.ipynb)
|
2021-12-22 08:54:04 +00:00
|
|
|
script demonstrates the integration of ClearML's explicit reporting module, `Logger`, in a Jupyter Notebook. All ClearML
|
2021-05-13 23:48:51 +00:00
|
|
|
explicit reporting works with Jupyter Notebook.
|
|
|
|
|
|
|
|
This example includes several types of explicit reporting, including:
|
|
|
|
* Scalars
|
|
|
|
* Some plots
|
|
|
|
* Media.
|
|
|
|
|
|
|
|
:::note
|
|
|
|
In the ``clearml`` GitHub repository, this example includes a clickable icon to open the notebook in Google Colab.
|
|
|
|
:::
|
|
|
|
|
|
|
|
## Scalars
|
|
|
|
|
2023-11-15 10:11:28 +00:00
|
|
|
To reports scalars, call [`Logger.report_scalar()`](../../references/sdk/logger.md#report_scalar).
|
2023-11-05 08:30:37 +00:00
|
|
|
The scalar plots appear in the **web UI** in **SCALARS**.
|
2021-05-13 23:48:51 +00:00
|
|
|
|
2021-12-22 08:54:04 +00:00
|
|
|
```python
|
|
|
|
# report two scalar series on two different graphs
|
|
|
|
for i in range(10):
|
2024-08-12 13:04:50 +00:00
|
|
|
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))
|
2021-12-22 08:54:04 +00:00
|
|
|
```
|
2021-05-13 23:48:51 +00:00
|
|
|
|
2021-12-22 08:54:04 +00:00
|
|
|

|
2021-05-13 23:48:51 +00:00
|
|
|
|
2021-12-22 08:54:04 +00:00
|
|
|
```python
|
|
|
|
# report two scalar series on the same graph
|
|
|
|
for i in range(10):
|
2024-08-12 13:04:50 +00:00
|
|
|
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))
|
2021-12-22 08:54:04 +00:00
|
|
|
```
|
2021-05-13 23:48:51 +00:00
|
|
|
|
2021-12-22 08:54:04 +00:00
|
|
|

|
2021-05-13 23:48:51 +00:00
|
|
|
|
|
|
|
## Plots
|
|
|
|
|
2022-05-22 07:27:30 +00:00
|
|
|
Plots appear in **PLOTS**.
|
2021-05-13 23:48:51 +00:00
|
|
|
|
|
|
|
### 2D Plots
|
|
|
|
|
2023-11-15 10:11:28 +00:00
|
|
|
Report 2D scatter plots by calling [`Logger.report_scatter2d()`](../../references/sdk/logger.md#report_scatter2d).
|
2021-05-13 23:48:51 +00:00
|
|
|
Use the `mode` parameter to plot data points as markers, or both lines and markers.
|
|
|
|
|
2021-12-22 08:54:04 +00:00
|
|
|
```python
|
|
|
|
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(
|
2024-03-06 13:00:50 +00:00
|
|
|
title="example_scatter",
|
|
|
|
series="series_lines+markers",
|
2021-12-22 08:54:04 +00:00
|
|
|
iteration=iteration,
|
|
|
|
scatter=scatter2d,
|
|
|
|
xaxis="title x",
|
|
|
|
yaxis="title y",
|
|
|
|
mode='lines+markers'
|
|
|
|
)
|
|
|
|
```
|
|
|
|
|
|
|
|

|
2021-05-13 23:48:51 +00:00
|
|
|
|
|
|
|
### 3D Plots
|
|
|
|
|
2023-11-15 10:11:28 +00:00
|
|
|
To plot a series as a 3D scatter plot, use [`Logger.report_scatter3d()`](../../references/sdk/logger.md#report_scatter3d).
|
2021-05-13 23:48:51 +00:00
|
|
|
|
2021-12-22 08:54:04 +00:00
|
|
|
```python
|
|
|
|
# report 3d scatter plot
|
|
|
|
scatter3d = np.random.randint(10, size=(10, 3))
|
|
|
|
logger.report_scatter3d(
|
2024-03-06 13:00:50 +00:00
|
|
|
title="example_scatter_3d",
|
|
|
|
series="series_xyz",
|
2021-12-22 08:54:04 +00:00
|
|
|
iteration=iteration,
|
|
|
|
scatter=scatter3d,
|
|
|
|
xaxis="title x",
|
|
|
|
yaxis="title y",
|
|
|
|
zaxis="title z",
|
|
|
|
)
|
|
|
|
```
|
|
|
|
|
|
|
|

|
2021-05-13 23:48:51 +00:00
|
|
|
|
2023-11-15 10:11:28 +00:00
|
|
|
To plot a series as a surface plot, use [`Logger.report_surface()`](../../references/sdk/logger.md#report_surface).
|
2021-05-13 23:48:51 +00:00
|
|
|
|
2021-12-22 08:54:04 +00:00
|
|
|
```python
|
|
|
|
# report 3d surface
|
|
|
|
surface = np.random.randint(10, size=(10, 10))
|
|
|
|
logger.report_surface(
|
2024-03-06 13:00:50 +00:00
|
|
|
title="example_surface",
|
|
|
|
series="series1",
|
2021-12-22 08:54:04 +00:00
|
|
|
iteration=iteration,
|
|
|
|
matrix=surface,
|
|
|
|
xaxis="title X",
|
|
|
|
yaxis="title Y",
|
|
|
|
zaxis="title Z",
|
|
|
|
)
|
|
|
|
```
|
|
|
|
|
|
|
|

|
2021-05-13 23:48:51 +00:00
|
|
|
|
2021-09-09 10:17:46 +00:00
|
|
|
### Confusion Matrices
|
2021-05-13 23:48:51 +00:00
|
|
|
|
2023-10-11 09:29:56 +00:00
|
|
|
Report confusion matrices by calling [`Logger.report_confusion_matrix()`](../../references/sdk/logger.md#report_confusion_matrix).
|
2021-05-13 23:48:51 +00:00
|
|
|
|
2021-12-22 08:54:04 +00:00
|
|
|
```python
|
|
|
|
# report confusion matrix
|
|
|
|
confusion = np.random.randint(10, size=(10, 10))
|
2023-10-11 09:29:56 +00:00
|
|
|
logger.report_confusion_matrix(
|
2024-03-06 13:00:50 +00:00
|
|
|
title="example_confusion",
|
|
|
|
series="ignored",
|
2021-12-22 08:54:04 +00:00
|
|
|
iteration=iteration,
|
|
|
|
matrix=confusion,
|
|
|
|
xaxis="title X",
|
|
|
|
yaxis="title Y",
|
|
|
|
)
|
|
|
|
```
|
|
|
|
|
|
|
|

|
2021-05-13 23:48:51 +00:00
|
|
|
|
|
|
|
### Histograms
|
|
|
|
|
2023-10-11 09:29:56 +00:00
|
|
|
Report histograms by calling [`Logger.report_histogram()`](../../references/sdk/logger.md#report_histogram).
|
|
|
|
To report more than one series on the same plot, use the same `title` argument.
|
2021-05-13 23:48:51 +00:00
|
|
|
|
2021-12-22 08:54:04 +00:00
|
|
|
```python
|
|
|
|
# report a single histogram
|
|
|
|
histogram = np.random.randint(10, size=10)
|
|
|
|
logger.report_histogram(
|
2024-03-06 13:00:50 +00:00
|
|
|
title="single_histogram",
|
|
|
|
series="random histogram",
|
2021-12-22 08:54:04 +00:00
|
|
|
iteration=iteration,
|
|
|
|
values=histogram,
|
|
|
|
xaxis="title x",
|
|
|
|
yaxis="title y",
|
|
|
|
)
|
|
|
|
```
|
2021-05-13 23:48:51 +00:00
|
|
|
|
2021-12-22 08:54:04 +00:00
|
|
|

|
2021-05-13 23:48:51 +00:00
|
|
|
|
2021-12-22 08:54:04 +00:00
|
|
|
```python
|
|
|
|
# report a two histograms on the same plot
|
|
|
|
histogram1 = np.random.randint(13, size=10)
|
|
|
|
histogram2 = histogram * 0.75
|
|
|
|
logger.report_histogram(
|
2024-03-06 13:00:50 +00:00
|
|
|
title="two_histogram",
|
|
|
|
series="series 1",
|
2021-12-22 08:54:04 +00:00
|
|
|
iteration=iteration,
|
|
|
|
values=histogram1,
|
|
|
|
xaxis="title x",
|
|
|
|
yaxis="title y",
|
|
|
|
)
|
|
|
|
logger.report_histogram(
|
2024-03-06 13:00:50 +00:00
|
|
|
title="two_histogram",
|
|
|
|
series="series 2",
|
2021-12-22 08:54:04 +00:00
|
|
|
iteration=iteration,
|
|
|
|
values=histogram2,
|
|
|
|
xaxis="title x",
|
|
|
|
yaxis="title y",
|
|
|
|
)
|
|
|
|
```
|
|
|
|
|
|
|
|

|
2021-05-13 23:48:51 +00:00
|
|
|
|
|
|
|
## Media
|
|
|
|
|
2023-10-11 09:29:56 +00:00
|
|
|
Report audio, HTML, image, and video by calling [`Logger.report_media()`](../../references/sdk/logger.md#report_media)
|
|
|
|
using the `local_path` parameter. They appear in **DEBUG SAMPLES**.
|
2021-05-13 23:48:51 +00:00
|
|
|
|
2023-10-11 09:29:56 +00:00
|
|
|
The media for these examples is downloaded using [`StorageManager.get_local_copy()`](../../references/sdk/storage.md#storagemanagerget_local_copy).
|
2021-05-13 23:48:51 +00:00
|
|
|
|
|
|
|
For example, to download an image:
|
|
|
|
|
2021-12-22 08:54:04 +00:00
|
|
|
```python
|
|
|
|
image_local_copy = StorageManager.get_local_copy(
|
|
|
|
remote_url="https://pytorch.org/tutorials/_static/img/neural-style/picasso.jpg",
|
|
|
|
name="picasso.jpg"
|
|
|
|
)
|
|
|
|
```
|
2021-05-13 23:48:51 +00:00
|
|
|
|
|
|
|
### Audio
|
|
|
|
|
2021-12-22 08:54:04 +00:00
|
|
|
```python
|
2024-03-06 13:00:50 +00:00
|
|
|
logger.report_media(title='audio', series='pink panther', iteration=1, local_path=audio_local_copy)
|
2021-12-22 08:54:04 +00:00
|
|
|
```
|
2021-05-13 23:48:51 +00:00
|
|
|
|
2021-12-22 08:54:04 +00:00
|
|
|

|
2021-05-13 23:48:51 +00:00
|
|
|
|
|
|
|
### HTML
|
|
|
|
|
2021-12-22 08:54:04 +00:00
|
|
|
```python
|
2022-01-23 07:50:24 +00:00
|
|
|
logger.report_media(
|
2024-03-06 13:00:50 +00:00
|
|
|
title="html",
|
|
|
|
series="url_html",
|
2022-01-23 07:50:24 +00:00
|
|
|
iteration=1,
|
|
|
|
url="https://clear.ml/docs/latest/docs/index.html"
|
|
|
|
)
|
2021-12-22 08:54:04 +00:00
|
|
|
```
|
2021-05-13 23:48:51 +00:00
|
|
|
|
2021-12-22 08:54:04 +00:00
|
|
|

|
2021-05-13 23:48:51 +00:00
|
|
|
|
|
|
|
### Images
|
|
|
|
|
2021-12-22 08:54:04 +00:00
|
|
|
```python
|
2024-03-06 13:00:50 +00:00
|
|
|
logger.report_image(
|
|
|
|
title="image",
|
|
|
|
series="image from url",
|
|
|
|
iteration=100,
|
|
|
|
local_path=image_local_copy
|
|
|
|
)
|
2021-12-22 08:54:04 +00:00
|
|
|
```
|
2021-05-13 23:48:51 +00:00
|
|
|
|
2021-12-22 08:54:04 +00:00
|
|
|

|
2021-05-13 23:48:51 +00:00
|
|
|
|
|
|
|
### Video
|
|
|
|
|
2021-12-22 08:54:04 +00:00
|
|
|
```python
|
2024-03-06 13:00:50 +00:00
|
|
|
logger.report_media(
|
|
|
|
title='video',
|
|
|
|
series='big bunny',
|
|
|
|
iteration=1,
|
|
|
|
local_path=video_local_copy
|
|
|
|
)
|
2021-12-22 08:54:04 +00:00
|
|
|
```
|
2021-05-13 23:48:51 +00:00
|
|
|
|
2021-12-22 08:54:04 +00:00
|
|
|

|
2021-05-13 23:48:51 +00:00
|
|
|
|
|
|
|
## Text
|
|
|
|
|
2023-10-11 09:29:56 +00:00
|
|
|
Report text messages by calling [`Logger.report_text()`](../../references/sdk/logger.md#report_text).
|
2021-05-13 23:48:51 +00:00
|
|
|
|
2021-12-22 08:54:04 +00:00
|
|
|
```python
|
|
|
|
logger.report_text("hello, this is plain text")
|
|
|
|
```
|
|
|
|
|
|
|
|

|