MNIST

This section covers the MNIST use case. This use case has been implemented using three different strategies, TensorFlow, PyTorch and PyTorch Lightning. You can find the files relevant to this use case in the use case’s folder on Github.

For more information on each implementation, consult their respective READMEs:

Torch Lightning

Integration author(s): Matteo Bunino (CERN)

Training

# Download dataset and exit: only run first step in the pipeline (index=0)
itwinai exec-pipeline --config config.yaml --pipe-key training_pipeline --steps 0

# Run the whole training pipeline
itwinai exec-pipeline --config config.yaml --pipe-key training_pipeline

View training logs on MLFLow server (if activated from the configuration):

mlflow ui --backend-store-uri mllogs/mlflow/

PyTorch

Integration author(s): Matteo Bunino (CERN)

Training

# Download dataset and exit
itwinai exec-pipeline --config config.yaml --pipe-key training_pipeline --steps dataloading_step

# Run the whole training pipeline
itwinai exec-pipeline --config config.yaml --pipe-key training_pipeline

View training logs on MLFLow server (if activated from the configuration):

mlflow ui --backend-store-uri mllogs/mlflow/

Inference

  1. Create sample dataset

    from dataloader import InferenceMNIST
    InferenceMNIST.generate_jpg_sample('mnist-sample-data/', 10)
    
  2. Generate a dummy pre-trained neural network

    import torch
    from model import Net
    dummy_nn = Net()
    torch.save(dummy_nn, 'mnist-pre-trained.pth')
    
  3. Run inference command. This will generate a β€œmnist-predictions” folder containing a CSV file with the predictions as rows.

    itwinai exec-pipeline --config config.yaml --pipe-key inference_pipeline
    

Note the same entry point as for training.

Docker image

Build from project root with

# Local
docker buildx build -t itwinai:0.0.1-mnist-torch-0.1 -f use-cases/mnist/torch/Dockerfile .

# Ghcr.io
docker buildx build -t ghcr.io/intertwin-eu/itwinai:0.0.1-mnist-torch-0.1 -f use-cases/mnist/torch/Dockerfile .
docker push ghcr.io/intertwin-eu/itwinai:0.0.1-mnist-torch-0.1

Training with Docker container

docker run -it --rm --name running-inference \
    -v "$PWD":/usr/data ghcr.io/intertwin-eu/itwinai:0.01-mnist-torch-0.1 \
    /bin/bash -c "itwinai exec-pipeline --print-config \
    --config /usr/src/app/config.yaml \
    --pipe-key training_pipeline \
    -o dataset_root=/usr/data/mnist-dataset "

Inference with Docker container

From wherever a sample of MNIST jpg images is available (folder called β€˜mnist-sample-data/’):

β”œβ”€β”€ $PWD
β”‚   β”œβ”€β”€ mnist-sample-data
|   β”‚   β”œβ”€β”€ digit_0.jpg
|   β”‚   β”œβ”€β”€ digit_1.jpg
|   β”‚   β”œβ”€β”€ digit_2.jpg
...
|   β”‚   β”œβ”€β”€ digit_N.jpg
docker run -it --rm --name running-inference \
    -v "$PWD":/usr/data ghcr.io/intertwin-eu/itwinai:0.01-mnist-torch-0.1 \
    /bin/bash -c "itwinai exec-pipeline --print-config \
    --config /usr/src/app/config.yaml \
    --pipe-key inference_pipeline \
    -o test_data_path=/usr/data/mnist-sample-data \
    -o inference_model_mlflow_uri=/usr/src/app/mnist-pre-trained.pth \
    -o predictions_dir=/usr/data/mnist-predictions "

This command will store the results in a folder called β€œmnist-predictions”:

β”œβ”€β”€ $PWD
β”‚   β”œβ”€β”€ mnist-predictions
|   β”‚   β”œβ”€β”€ predictions.csv