Examples

The Trains repository examples directory contains Python scripts demonstrating Trains for Keras, PyTorch, and TensorFlow deep learning frameworks, as well as Jupyter Notebook integration and custom examples, including reporting metrics and configuring models. You can run the example scripts and view their results on the Trains Web-App.

This page describes the examples, including a link for each example script, and a list of the Trains Web-App experiment details panel tabs where you can find the results demonstrating each example's features.

For each example, only two lines of Trains integration code, were added:

from trains import Task
task = Task.init(project_name=”examples”, task_name=”description”)

Running and viewing examples

Use the procedure in this section to run experiments in the Trains repository examples directory, except those in the examples/automl subdirectory. The automl experiments require additional steps which are not shown in this section. For the steps to run an automl example, see our AutoML tutorial.

To run an example experiment and view the results, do the following:

  1. If you have not cloned the trains repository, clone it.
  2. In your local trains repository, run an example Python script.
  3. View the experiment in the Trains Web-App by doing either of the following:
    • From the console, Trains outputs a TRAINS results page URL. Click the TRAINS results page URL or copy / paste it to your browser. The Trains Web-App opens showing your experiment.
    • In your browser, open the Trains Web-App (either our demo Trains Server https://demoapp.trains.allegro.ai/dashboard, or your own locally-host Trains Server, if you deployed one). On the Home page, click the experiment, or on the Projects page, click the examples project card and then click experiment. The details panel slides open.

Keras Examples

Keras with TensorBoard - MNIST Training

keras_tensorboard.py is an example of training a small convolutional NN on the MNIST DataSet.

The details panel tabs showing the features of this example:

  • HYPER PARAMETERS - Command line arguments.
  • ARTIFACTS
    • Input model, if the experiment is executed for the second time, then this is a link to the input model details on the Projects page, models table.
    • Creating experiment (experiment creating this model). This is a link to that experiment's details on the Projects page, experiments table.
    • Output model and configuration.
  • RESULTS
    • SCALARS - Accuracy/loss scalar metric graphs.
    • PLOTS - Convolution weights histograms.
    • LOG - Console standard output/error.

Pytorch Examples

PyTorch - MNIST Training

pytorch_mnist.py is an example of PyTorch MNIST training integration.

The details panel tabs showing the features of this example:

  • HYPER PARAMETERS - Command line arguments.
  • ARTIFACTS
    • Input model, if the experiment is executed for the second time, then this is a link to the input model details on the Projects page, models table.
    • Creating experiment (experiment creating this model). This is a link to that experiment's details on the Projects page, experiments table.
    • Output model is a link to the output model details in the Projects page, models table.
  • RESULTS
  • LOG - Console standard output/error

PyTorch and Matplotlib - Testing Style Transfer

pytorch_matplotlib.py is an example of connecting the neural style transfer from the official PyTorch tutorial to TRAINS. Neural-Style, or Neural-Transfer, allows you to take an image and reproduce it with a new artistic style. The algorithm takes three images, an input-image, a content-image, and a style-image, and changes the input-image to resemble the content of the content-image and the artistic style of the style-image.

The details panel tabs showing the features of this example:

  • HYPER PARAMETERS - Command line arguments.
  • ARTIFACTS
    • Input model, if the experiment is executed for the second time, then this is a link to the input model details on the Projects page, models table.
    • Output model is a link to the output model details in the Projects page, models table.
  • RESULTS
    • DEBUG IMAGES - Input image, input style images, an output transferred style image.
    • LOG - Console standard output/error.

PyTorch with Tensorboard - MNIST Train

pytorch_tensorboard.py is an example of PyTorch MNIST training running with TensorBoard.

The details panel tabs showing the features of this example:

  • HYPER PARAMETERS - Command line arguments.
  • ARTIFACTS
    • Input model, if the experiment is executed for the second time, then this is a link to the input model details on the Projects page, models table.
    • Creating experiment (experiment creating this model). This is a link to that experiment's details on the Projects page, experiments table.
    • Output model (a link to the output model details on the Projects page, models table).
  • RESULTS
    • SCALARS - Train and test loss scalars.
    • LOG - Console standard output/error.

PyTorch with TensorBoardX - MNIST Train

pytorch_tensorboardX.py is an example of PyTorch MNIST training running with TensorBoardX.

The details panel tabs showing the features of this example:

  • HYPER PARAMETERS - Command line arguments.
  • ARTIFACTS
    • Input model, if the experiment is executed for the second time, then this is a link to the input model details on the Projects page, models table.
    • Creating experiment (experiment creating this model). This is a link to that experiment's details on the Projects page, experiments table.
    • Output model (a link to the output model details on the Projects page, models table).
  • RESULTS
    • SCALARS - Train and test loss scalars.
    • LOG - Console standard output/error.

TensorFlow Examples

TensorBoard with TensorFlow (without Training)

tensorboard_toy.py is a toy example of TensorBoard.

The details panel tabs showing the features of this example:

  • HYPER PARAMETERS - Command line arguments.
  • RESULTS
    • SCALARS - Random variable samples scalars.
    • PLOTS - Random variable samples histograms.
    • DEBUG IMAGES - Test images.
    • LOG - Console standard output/error.

TensorFlow in Eager Mode

tensorflow_eager.py is an example of running TensorFlow in eager mode.

The details panel tabs showing the features of this example:

  • HYPER PARAMETERS - Command line arguments.
  • RESULTS
    • SCALARS - Generator and discriminator loss.
    • DEBUG IMAGES - Generated images.
    • LOG - Console standard output/error.

TensorBoard Plugin - Precision Recall Curves

tensorboard_pr_curve.py is an example of TensorBoard precision recall curves.

The details panel tabs showing the features of this example:

  • HYPER PARAMETERS - Command line arguments.
  • RESULTS
    • PLOTS - Precision recall curves.
    • DEBUG IMAGES - Generated images.
    • LOG - Console standard output/error.

Hyper Parameters / TensorFlow Flags / absl

hyper_parameters_example.py is an example of toy TensorFlow FLAGS logging with absl package (absl-py) coupled with a hyperparameters dictionary.

The details panel tabs showing the features of this example:

  • HYPER PARAMETERS - TensorFlow flags with TF_DEFINE/ prefixes.
  • RESULTS
    • LOG - Console standard output/error.

TensorFlow MNIST Classifier with TensorBoard Reports

tensorflow_mnist_with_summaries.py is an example of TensorFlow MNIST with TensorBoard summary, model storage, and logging.

The details panel tabs showing the features of this example:

  • HYPER PARAMETERS - Command line arguments.
  • ARTIFACTS
    • Output model (a link to the output model details on the Projects page, models table).
  • RESULTS
    • SCALARS - Network statistics across the training steps (e.g., cross entropy, dropout, and specific layer statistics).
    • PLOTS - Convolutional layer histogram.
    • DEBUG IMAGES - Sample of the network input images.
    • LOG - Console standard output/error.

Jupyter Notebook Example

jupyter.ipynb is an example of integrating matplotlib and training with Keras on Jupyter Notebook. This example connects a parameter dictionary, prints simple graphs, and trains an MNIST classifier using Keras.

The details panel tabs showing the features of this example:

  • HYPER PARAMETERS - Parameter dictionary.
  • ARTIFACTS
    • Output model (a link to the output model details on the Projects page, models table).
    • Output model (a link to the Model Configuration).
  • RESULTS
    • SCALARS - Training loss across iterations.
    • PLOTS - Sine and circles plots, convolution weights histogram.
    • LOG - Console standard output/error.

Custom Examples

Manual Reporting

manual_reporting.py is an example of manually reporting graphs and statistics.

The details panel tabs showing the features of this example:

  • RESULTS
    • SCALARS - Scalar graphs.
    • PLOTS - Confusion matrix, histogram, 2D scatter plot, 3D scatter plot.
    • DEBUG IMAGES - Uploaded example images.
    • LOG - Console standard output/error.

Also, see our Explicit Reporting tutorial.

Manual Model Configuration

manual_model_config.py is an example of manually configuring a model, model storage, label enumeration values, and logging.

The details panel tabs showing the features of this example:

  • ARTIFACTS
    • Output model (a link to the output model details on the Projects page, models table, including label enumeration values).
    • Model Configuration.
  • RESULTS
    • LOG - Console standard output/error.