A simple CNN model for MNIST using PyTorch framework in a Docker container based on official PyTorch tutorial.
Pull image from DockerHub with:
docker pull alikhil/mnist:latest
MNIST model supports three modes:
fit – fitting a new modelpredict – making an inference on a valid inputeval – evaluating a model on a valid input with labelsNote: prediction and evaluation can only run after the fit.
The general command for running the image is:
docker run -t --rm \
-v volume-mnist:/app/state \
-v "$(pwd)"/data:/app/data \
alikhil/mnist:latest \
--mode [running mode (default: fit)] \
--batch-size [(optinal) training batch_size] \
--epochs [(optinal) number of training epochs] \
--model-path [(optinal) path to save the model]
Model parameters are saved at /app/state inside a container.
To use the same model across multiple runs,
option -v volume-mnist:/app/state is necessary.
To use own train or test data, create a directory data with files
inside your current working directory and
use -v "$(pwd)"/data:/app/data with docker run.
fitdocker run -t --rm -v volume-mnist:/app/state alikhil/mnist:latest --mode fit
X_train.npy and y_train.npy,
add files to directory ./data on your host machine and use:docker run -t --rm \
-v volume-mnist:/app/state \
-v "$(pwd)"/data:/app/data \
alikhil/mnist:latest --mode fit
Note: If input files X_train.npy and y_train.npy are not found or invalid,
original MNIST train data will be used.
predictdocker run -t --rm \
-v volume-mnist:/app/state \
alikhil/mnist:latest --mode predict
X_test.npy,
add file to directory ./data on your host machine and use::docker run -t --rm \
-v volume-mnist:/app/state -v "$(pwd)"/data:/app/data \
alikhil/mnist:latest --mode predict
Inference results will be saved at data/y_pred.npy.
Note: if input file X_test.npy is not found or invalid,
original MNIST test data will be used.
evaldocker run -t --rm \
-v volume-mnist:/app/state \
alikhil/mnist:latest --mode eval
X_test.npy and y_test.npy,
add these files to directory ./data on your host machine and use::docker run -t --rm \
-v volume-mnist:/app/state -v "$(pwd)"/data:/app/data \
alikhil/mnist:latest --mode eval
Note: If input files X_test.npy and y_test.npy are not found or invalid,
original MNIST test data will be used.
Content type
Image
Digest
Size
222 MB
Last updated
over 7 years ago
docker pull alikhil/mnist