This project is a web service that uses a machine learning model to predict digits from images. The service is built using FastAPI and provides two main API endpoints for prediction: for a single image and for multiple images (including zip archives).
src/app.py
: Main application file containing the API endpoints.src/ml.py
: Module containing functions for feature extraction and digit prediction.models/svm.pkl
: Saved SVM model for digit prediction.test/test.py
: Test suite for verifying API functionality.docker/Dockerfile
: Dockerfile for building the application container.src/requirements.txt
: List of Python dependencies.Makefile
: Scripts for building and running the Docker container.
- Ensure you have Python 3.10 installed.
- Install the dependencies:
pip install -r src/requirements.txt
- Run the application:
python src/app.py
Web-service will be available at http://127.0.0.1:8000/
- Build the Docker image:
make build
- Run the container:
make run
- Method: POST
- URL:
/predict
- Parameters: Image file in PNG format
- Response: JSON with predicted digit and confidence
- Method: POST
- URL:
/predict_batch
- Parameters: List of image files or a zip archive
- Response: JSON with predicted digits and confidence for each image
- Method: GET
- URL:
/health
- Response: JSON with service status
To run the tests, use the command:
python -m unittest discover -s test
The machine learning model is trained using SVM and saved in the models/svm.pkl
file. It uses HOG features for digit prediction.
- Ensure the model file
svm.pkl
is located in themodels
directory. - All dependencies listed in
requirements.txt
must be installed for the service to function correctly.
- Fine-tune hyperparameters of HOG feature extractor and the SVM classifier;
- Or use simple CNN model for digit classification;
- Put trained model on S3 storage and download it on startup;
- Add authentication and authorization;
- Add CI/CD pipeline;
- Connect Sentry for monitoring and logging;
- Implement asynchronous processing of requests (i.e. queue);
- Add swagger documentation.