This project uses a pre-trained Keras model to predict images through a FastAPI endpoint.
NOTE
Copy the model file to the root directory of the project. Ensure the model file is namedCNN_BF_PY.h5
, or adjust the filename in accordance with your model as specified in theapp/core/config.py
file.
run the following command in the terminal to setup the project:
docker-compose up -d --build
need to have the following tools installed for h5py:
sudo apt-get install pkg-config
sudo apt-get install libhdf5-dev
-
Create a virtual environment:
python -m venv env
-
Activate the virtual environment:
- On Windows:
.\env\Scripts\activate
- On Unix or MacOS:
source env/bin/activate
- On Windows:
-
Install the required dependencies:
pip install -r requirements.txt
-
Run the FastAPI application:
python3 -m uvicorn main:app
or for development with hot reloading:
uvicorn main:app --reload
-
Go to
http://127.0.0.1:8000
to see the welcome message. -
Use the
/predict/
endpoint to make predictions.example:
curl --location 'http://localhost:8000/predict' \ --form 'file=@"/path_to_img/1_2.jpg"'
response:
{"prediction":[[0.13054095208644867,0.13108479976654053,0.14114101231098175,0.09955856949090958,0.11344218999147415,0.06351987272500992,0.03114495612680912,0.08905033767223358,0.03987095132470131,0.07407043874263763,0.08657591044902802]]}