Skip to content

se4ai-lecture/ml-api-docker-container-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Creating a Custom Inference API

(You can work in pairs, if you want to.)

Your task is to create an inference Web API that checks if an image contains a cat. This starting project already provides the ML functionality for this (src/CatPredictor.py), namely a class that uses two pretrained models from the ImageNet family (VGG16 and MobileNet). You can see an example of its usage in src/usage-example.py. An advanced skeleton for the API you should build is provided based on the Flask framework in src/prediction-api.py. You can use the HTTP client of your choice to test it, e.g., Postman or curl. Once your API is ready, encapsulate it into a Docker image, and build and run a container with it.

Bonus task if you are quick: change your client project from last tutorial to use your newly created API instead of the Google Cloud Vision API for identifying all cats from the image set.

Prerequisites

  1. Install Python 3, preferably >= 3.9
  2. Install dependencies: pip install -r requirements.txt
  3. Install Docker Desktop (for the container part)

Usage

# using the prediction example (you can change the used filename to a different file under `images`)
python src/usage-example.py

# using the REST API
# set an ENV variable for the Flask entrypoint file
export FLASK_APP=src/prediction-api.py
# start the API --> API offers the endpoint `POST http://localhost:5000/cat-predictions`
flask run
# for enabling hot reload (execute before starting)
export FLASK_ENV=development

About

Tutorial of the M.Sc. lecture "Software Engineering for AI-based Systems" (SE4AI)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages