Creating an API and making predictions on a local server
In this section, we will learn about making predictions on a local server (that has nothing to do with the cloud). At a high level, this involves the following steps:
- Installing FastAPI
- Creating a route to accept incoming requests
- Saving an incoming request on disk
- Loading the requested image, and then preprocessing and predicting with the trained model
- Postprocessing the results and sending back the predictions as a response to the same incoming request
All of the steps in this section are summarized as a video walk-through here: https://tinyurl.com/MCVP-Model2FastAPI.
Let’s begin by installing FastAPI.
Installing the API module and dependencies
Since FastAPI is a Python module, we can use pip
for installation and get ready to code an API. We will now open a new terminal and run the following command:
$pip install fastapi uvicorn aiofiles jinja2...