Skip to content
An example mnist model
Branch: master
Clone or download
Pull request Compare This branch is 6 commits ahead, 58 commits behind Paperspace:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

MNIST in TensorFlow

This is random, minor change to try triggering an experiment. This directory builds a convolutional neural net to classify the MNIST dataset using the, tf.estimator.Estimator, and tf.layers APIs.


To begin, you'll simply need the latest version of TensorFlow installed. First make sure you've added the models folder to your Python path; otherwise you may encounter an error like ImportError: No module named mnist.

Then to train the model, run the following:


Distributed Training on Gradient

Just run the example with following parameters:

  "name": "Mnist Sample",
  "projectHandle": "<your project handle",
  "parameterServerContainer": "tensorflow/tensorflow:1.13.1-gpu-py3",
  "parameterServerMachineType": "K80",
  "parameterServerCount": 1,
  "workerCommand": "python",
  "workerContainer": "tensorflow/tensorflow:1.13.1-gpu-py3",
  "workspaceUrl": "git+",
  "workerMachineType": "K80",
  "workerCount": 2,
  "parameterServerCommand": "python"

Gradient will generate TF_CONFIG in base64 format for each node so all you need to do in your other projects:

paperspace_tf_config = json.loads(base64.urlsafe_b64decode(os.environ.get('TF_CONFIG')).decode('utf-8'))

Exporting the model

You can export the model into Tensorflow SavedModel format by using the argument --export_dir:

python --export_dir /tmp/mnist_saved_model

Training the model for use with Tensorflow Serving on a CPU

If you are training on Tensorflow using a GPU but would like to export the model for use in Tensorflow Serving on a CPU-only server you can train and/or export the model using --data_format=channels_last:

python --data_format=channels_last

The SavedModel will be saved in a timestamped directory under /tmp/mnist_saved_model/ (e.g. /tmp/mnist_saved_model/1513630966/).

Getting predictions with SavedModel Use saved_model_cli to inspect and execute the SavedModel.

You can’t perform that action at this time.