Skip to content

tsailiming/s2i-python-pytorch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

This is a demo repository for my blog series for Data Science on Medium.

S2I

S2I is used to build the following:

  1. Base Image

  2. Training image for MNIST

  3. Flask app for model serving

  4. Node.js frontend

Building

To build the base image with only Pytorch

$ s2i build pytorch registry.access.redhat.com/ubi8/python-38 --as-dockerfile=/tmp/pytorch/Dockerfile
$ cd /tmp/pytorch/ && buildah bud -f . -t pytorch:l.6.0

To build the training image:

$ s2i build mnist-flask-app/mnist pytorch:l.6.0 --as-dockerfile=/tmp/mnist/Dockerfile
$ cd /tmp/mnist/ && buildah bud -f . -t pytorch-mnist:latest

Once the model is trained, you can wrap it in flask app:

$ s2i build mnist-flask-app registry.access.redhat.com/ubi8/python-38 --as-dockerfile=/tmp/flask-app/Dockerfile
$ cp /tmp/model/mnist_cnn.pt /tmp/flask-app/upload/src/model/
$ cd /tmp/flask-app/ && buildah bud -f . -t mnist-flask:l.0

Alternatively, you can just build with the provided Dockerfile.

To build the Node.js frontend:

  $ s2i build . registry.redhat.io/ubi8/nodejs-14 --as-dockerfile=/tmp/mnist-draw/Dockerfile
  $ cd /tmp/mnist-draw/ && buildah bud -f . -t mnist-draw:1.0

Training

To run the training image via podman and an output folder:

$ podman run -it --rm -v /tmp/model:/model:Z pytorch-mnist:latest

MNIST Draw

MNIST Draw is an Express JS frontend that allows the user to draw the number and then makes a JQuery call to the backend Flask app for model inference.

MNIST Draw

Follow the above instructions to build the images and run:

$ podman run -it --rm -p8080:8080 -e MNIST_SERVER=http://myserver.local:5000 localhost/mnist-draw:1.0
$ podman run -it --rm -p5000:5000 localhost/mnist-flask:1.0

The images are available from quay.io too:

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published