A FastAPI-based RESTful API that identifies a person's handwriting using a trained PyTorch ResNet18 model. Upload a handwriting image and get the predicted writer with confidence scores. This project is aimed at combating exam malpractice by verifying handwriting.
- Backend: FastAPI
- Machine Learning: PyTorch, Torchvision
- Image Processing: Pillow
- Server: Uvicorn
.
├── app/
│ ├── main.py # FastAPI application, endpoints
│ ├── model.py # Model loading and prediction logic
│ └── utils.py # Image preprocessing utilities
├── data/
│ └── handwriting_dataset_training/ # Training images
├── models/
│ └── handwriting_model.pt # Trained PyTorch model
├── .gitignore
├── README.md
├── requirements.txt # Project dependencies
└── train.py # Script to train the model
-
Clone the repository:
git clone https://github.com/your-username/Handwriting-Predictive-A.I.git cd Handwriting-Predictive-A.I -
Create a virtual environment and activate it:
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`
-
Install the dependencies:
pip install -r requirements.txt
-
Run the FastAPI server:
uvicorn app.main:app --reload
The application will be available at
http://127.0.0.1:8000. -
Use the prediction endpoint: You can use tools like
curlor the interactive API documentation athttp://127.0.0.1:8000/docsto send aPOSTrequest to the/predictendpoint with an image file.Example using
curl:curl -X POST -F "file=@/path/to/your/image.jpg" http://127.0.0.1:8000/predictSample Prediction Response:
{ "label": "Dubem_test", "confidence": 0.9873, "message": "This handwriting definitely belongs to Dubem_test." }
To train the model on your own dataset:
-
Prepare your dataset: Organize your training images in the
data/handwriting_dataset_trainingdirectory, with each subdirectory named after a class (e.g.,data/handwriting_dataset_training/new_person). -
Run the training script:
python train.py
The script will train the model and save the updated
handwriting_model.ptfile in themodels/directory. You can configure the training parameters (epochs, learning rate, etc.) at the top of thetrain.pyfile.