This project implements an end-to-end pipeline for building, training, and deploying a Cat-Dog Classifier using PyTorch and FastAPI. The classifier is based on a simple convolutional neural network (CNN) trained on the CIFAR-10 dataset.
- Data Preparation: Script to download and preprocess the CIFAR-10 dataset.
- Model Training: Train a CNN model to classify images into one of 10 categories.
- Model Deployment: Deploy the trained model as a REST API using FastAPI.
- Docker Support: Dockerfile provided for easy deployment.
cat_dog_classifier/
├── data/ # Directory for storing dataset
├── model/ # Directory for saving the trained model
├── scripts/ # Python scripts for data preparation and training
│ ├── data_prep.py # Script to download and preprocess the dataset
│ ├── train_model.py # Script to train the CNN model
├── app.py # FastAPI app for model inference
├── requirements.txt # Dependencies required for the project
├── Dockerfile # Dockerfile for deploying the API
- Python 3.8 or higher
- Pip
- PyTorch
- FastAPI
- Docker (optional, for containerization)
-
Clone the repository:
git clone <repository_url> cd cat_dog_classifier
-
Install the required dependencies:
pip install -r requirements.txt
Run the script to download and preprocess the CIFAR-10 dataset:
python scripts/data_prep.py
Train the CNN model:
python scripts/train_model.py
The trained model will be saved in the model/
directory as cat_dog_model.pth
.
Run the FastAPI app:
uvicorn app:app --reload
Access the API documentation at http://127.0.0.1:8000/docs.
Use the /predict
endpoint to classify an image. Example using curl
:
curl -X POST "http://127.0.0.1:8000/predict/" -H "accept: application/json" -H "Content-Type: multipart/form-data" -F "file=@path_to_image.jpg"
-
Build the Docker image:
docker build -t cat-dog-api .
-
Run the container:
docker run -p 8000:8000 cat-dog-api
-
Access the API at http://127.0.0.1:8000.
This project is licensed under the MIT License. See the LICENSE file for details.