Skip to content

This repo focuses on how to rapidly deploy your machine learning models with FastAPI, Redis and Docker.

Notifications You must be signed in to change notification settings

mosesmulwa-bebop/ML-model-deployment-using-Keras-FastAPI-Redis-and-Docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Details

This repo covers deployment of an image classification model(ResNet50) using FastAPI, Redis and Docker.

For an in-depth project on Residual Networks: Residual Networks

For a more detailed FastAPI project: Using FastAPI to build a full-fledged social media backend

This repo is based on this medium article: Medium Article

Deployment

  1. First docker-compose
   docker-compose up
  1. Test with sample image provided
   curl -X POST [email protected] http://localhost/predict

The sample Image Doge

  1. Response if everything run correctly.
Response (Code 200)
{"success":true,
"predictions":[
    {"label":"dingo","probability":0.5237663984298706},
    {"label":"Pembroke","probability":0.178588405251503},
    {"label":"basenji","probability":0.1512373834848404},
    {"label":"Eskimo_dog","probability":0.03126605227589607},
    {"label":"bath_towel","probability":0.011432502418756485}]}

Overview

  1. Building a web server using FastAPI (with Uvicorn) to serve as a machine learning endpoint.
  2. Building a machine learning model server that serves a Keras image classification model (ResNet50 trained on ImageNet).
  3. Using Redis as a message queue to pass queries and responses between the web server and model server.
  4. Using Docker Compose to spin them all up!

How it works

The main function of the web server is to serve a /predict endpoint through which other applications will call our machine learning model.
When the endpoint is called, the web server routes the request to the Redis, which acts as an in-memory message queue for many concurrent requests.
The model server simply polls the Redis message queue for a batch of images, classifies the batch of images, then returns the results to Redis. The web server picks up the results and returns that.

Contents

  1. Included Files
  2. Why FastAPI

Included Files

1. Webserver

Contains code for the webserver built using FastAPI Dockerfile - Docker file for copies the fastapi image and installing requirements. main.py - runs the FastAPI server, exposing the/predict endpoint which takes the uploaded image, serializes it, pushes it to Redis and polls for the resulting predictions. requirements.txt- contains all the requirements for the webserver.

Why FastAPI

FastAPI uses an ASGI(Asynchronous Server Gateway Interface) which means that requests are handled asynchronously. This means that they don't have to wait for others before them to finish doing their tasks.
FastAPI is also a micro web framework with many advantages, including out-of-the-box support for asynchronous code using the Python async and await keywords, and much more.

About

This repo focuses on how to rapidly deploy your machine learning models with FastAPI, Redis and Docker.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published