Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


A simple web service classifying MNIST digits from HTTP POST requests built using Flask, TensorFlow and TensorLayer

The API uses HTTP POST operations to classify images of handwritten MNIST digits that is sent in the request. The single POST request available is /mnist/classify. The API uses JSON for both requests and responses, see below for a detailed specification of the JSON data format. Currently the API only supports 28 by 28 grayscale images and only handles a set maximum batch size of images in each request (the max batch size is currently set as a constant in

JSON request format

The HTTP POST request /mnist/classify expects a JSON request. Example JSON data for the request:

        "image":"/9j/7QBEUGhvdG9...image contents...eYxxxzj/Coa6Bax//Z"
        "image":"/9j/7QBEUGhvdG9...image contents...eYxxxzj/Coa6Bax//Z"
  • requests - A list of requests, one for each image
    • image - The image data for this request provided as base64-encoded raw image data. The API only accepts 28 by 28 pixel grayscale images at the moment.

JSON response format

  • responses - A list of responses, one for each image
    • class - The type of digit the image represents [0-9]
    • probability - The inferred probability of the predicted class [0-1] (Softmax score)

Installing requirements

The API uses python3 and the requirements can be installed by

    $pip3 install -r requirements.txt

Running the server

The Flask application can be deployed using e.g. gunicorn using:

    $gunicorn server_application:app

Running the simple test client

After starting the server requests can be sent using the test client. For detailed use of the test client see:

    $python3 --help

Example use, downloading 10 MNIST images and submitting them as a request for classification to a local server:

    $python3 --download_mnist --server=

Training new model parameters

For convinience pretrained model parameters for the convolutional neural network is supplied in the model/ directory. However, the model can also be retrained by running the script in the model directory.

    $python3 python3


A simple webservice API for classifying MNIST digits from HTTP POST requests built using Flask and TensorFlow/Layer







No releases published


No packages published