Skip to content

Deployment of a deep learning model as REST API using Flask and Docker

License

Notifications You must be signed in to change notification settings

bagheri365/CatDog-Calssifier-Deployment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deployment of a Cat and Dog Image Classifier with Flask and Docker

In this repository, I share my practice in containerizing a Machine Learning (ML)/Deep Learning model as REST API using Flask and Docker.

Tools

  • Python (Tensorflow & Pillow)
  • Flask, HTML & CSS
  • Docker

Data

The data can be downloaded as the following:

wget --no-check-certificate \
  https://storage.googleapis.com/mledu-datasets/cats_and_dogs_filtered.zip \
  -O ./data/cats_and_dogs_filtered.zip

ML model

The ML model consists of data preprocessing, feature extraction and classifier. In the training phase, data augmentation and dropouts techniques are utitlized to improve the performance. Below is the block diagram of the deep learning model.

Figure: Cat vs Dog Classifier diagram.

The inception v3 weights can be accessed as the folowing:

wget --no-check-certificate \
    https://storage.googleapis.com/mledu-datasets/inception_v3_weights_tf_dim_ordering_tf_kernels_notop.h5 \
    -O ./data/inception_v3_weights_tf_dim_ordering_tf_kernels_notop.h5

Docker

Build a docker image

Clone the repository into your local machine as the following:

git clone https://github.com/bagheri365/CatDog-Calssifier-Deployment.git mygit
cd mygit

Build an image from the Dockerfile as the following:

docker build -t myimage:latest .

Note that a docker image is a template that contains the application, and all the dependencies required to run that application on Docker.

Run the docker container

You can run the docker container as the following:

docker run -it -p 5000:5000 myimage

Note that the container simply is running instance of the image.

Demos

Here are demos of the REST API built with Flask.