clearml-docs/docs/guides/frameworks/pytorch/pytorch_mnist.md
2022-05-26 09:54:41 +03:00

2.3 KiB
Raw Blame History

title
PyTorch MNIST

The pytorch_mnist.py example demonstrates the integration of ClearML into code that uses PyTorch.

The example script does the following:

  • Trains a simple deep neural network on the PyTorch built-in MNIST dataset.
  • Creates an experiment named pytorch mnist train, which is associated with the examples project.
  • 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 method.

Scalars

In the example script's train function, the following code explicitly reports scalars to ClearML:

Logger.current_logger().report_scalar(
    "train", "loss", iteration=(epoch * len(train_loader) + batch_idx), value=loss.item()
)

In the test method, the code explicitly reports loss and accuracy scalars.

Logger.current_logger().report_scalar(
    "test", "loss", iteration=epoch, value=test_loss
)
Logger.current_logger().report_scalar(
    "test", "accuracy", iteration=epoch, value=(correct / len(test_loader.dataset))
)

These scalars can be visualized in plots, which appear in the ClearML web UI, in the experiment's page > SCALARS.

image

Hyperparameters

ClearML automatically logs command line options defined with argparse. They appear in CONFIGURATION > HYPER PARAMETERS > Args.

image

Console

Text printed to the console for training progress, as well as all other console output, appear in CONSOLE.

image

Artifacts

Models created by the experiment appear in the experiments ARTIFACTS tab. ClearML automatically logs and tracks models and any snapshots created using PyTorch.

image

Clicking on the model name takes you to the models page, where you can view the models details and access the model.

image