clearml-docs/docs/guides/frameworks/pytorch/pytorch_mnist.md

63 lines
2.3 KiB
Markdown
Raw Normal View History

2021-05-13 23:48:51 +00:00
---
title: PyTorch MNIST
2021-05-13 23:48:51 +00:00
---
The [pytorch_mnist.py](https://github.com/allegroai/clearml/blob/master/examples/frameworks/pytorch/pytorch_mnist.py) example
2022-01-23 07:50:24 +00:00
demonstrates the integration of ClearML into code that uses PyTorch.
2021-05-13 23:48:51 +00:00
The example script does the following:
2021-08-31 08:09:29 +00:00
* Trains a simple deep neural network on the PyTorch built-in [MNIST](https://pytorch.org/vision/stable/datasets.html#mnist)
2021-05-13 23:48:51 +00:00
dataset.
* Creates an experiment named `pytorch mnist train`, which is associated with the `examples` project.
2022-01-13 07:42:36 +00:00
* ClearML automatically logs `argparse` command line options, and models (and their snapshots) created by PyTorch
* Additional metrics are logged by calling the [Logger.report_scalar](../../../references/sdk/logger.md#report_scalar) method.
2021-05-13 23:48:51 +00:00
## Scalars
2022-03-13 13:07:06 +00:00
In the example script's `train` function, the following code explicitly reports scalars to ClearML:
2021-05-13 23:48:51 +00:00
```python
Logger.current_logger().report_scalar(
2022-01-13 07:42:36 +00:00
"train", "loss", iteration=(epoch * len(train_loader) + batch_idx), value=loss.item()
)
2021-05-13 23:48:51 +00:00
```
In the `test` method, the code explicitly reports `loss` and `accuracy` scalars.
```python
Logger.current_logger().report_scalar(
2022-01-13 07:42:36 +00:00
"test", "loss", iteration=epoch, value=test_loss
)
2021-05-13 23:48:51 +00:00
Logger.current_logger().report_scalar(
2022-01-13 07:42:36 +00:00
"test", "accuracy", iteration=epoch, value=(correct / len(test_loader.dataset))
)
2021-05-13 23:48:51 +00:00
```
2022-01-16 09:13:53 +00:00
These scalars can be visualized in plots, which appear in the ClearML [web UI](../../../webapp/webapp_overview.md),
2022-05-22 07:27:30 +00:00
in the experiment's page **>** **SCALARS**.
2022-01-16 09:13:53 +00:00
2021-05-13 23:48:51 +00:00
![image](../../../img/examples_pytorch_mnist_07.png)
## Hyperparameters
2023-01-12 10:49:55 +00:00
ClearML automatically logs command line options defined with `argparse`. They appear in **CONFIGURATION** **>** **HYPERPARAMETERS** **>** **Args**.
2021-05-13 23:48:51 +00:00
![image](../../../img/examples_pytorch_mnist_01.png)
2021-05-18 22:31:01 +00:00
## Console
2021-05-13 23:48:51 +00:00
2022-05-22 07:27:30 +00:00
Text printed to the console for training progress, as well as all other console output, appear in **CONSOLE**.
2021-05-13 23:48:51 +00:00
![image](../../../img/examples_pytorch_mnist_06.png)
## Artifacts
2022-01-13 07:42:36 +00:00
Models created by the experiment appear in the experiments **ARTIFACTS** tab. ClearML automatically logs and tracks models
and any snapshots created using PyTorch.
2021-05-13 23:48:51 +00:00
![image](../../../img/examples_pytorch_mnist_02.png)
2022-01-13 07:42:36 +00:00
Clicking on the model name takes you to the [models page](../../../webapp/webapp_model_viewing.md), where you can view
the models details and access the model.
2021-05-13 23:48:51 +00:00
![image](../../../img/examples_pytorch_mnist_03.png)