{"id":15142622,"url":"https://github.com/lucapalminteri/mnist-digit-recognition-api","last_synced_at":"2026-02-11T12:01:47.950Z","repository":{"id":256317683,"uuid":"854925263","full_name":"LucaPalminteri/mnist-digit-recognition-api","owner":"LucaPalminteri","description":"A FastAPI-powered API for serving a Convolutional Neural Network (CNN) model trained on the MNIST dataset for handwritten digit recognition. The project leverages PyTorch for the model, and includes endpoints for prediction and serving, making it easy to integrate with other applications for real-time digit classification.","archived":false,"fork":false,"pushed_at":"2024-09-10T02:18:28.000Z","size":609,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-22T12:41:57.786Z","etag":null,"topics":["ai","api-rest","fastapi","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LucaPalminteri.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-10T02:06:41.000Z","updated_at":"2024-09-10T02:18:31.000Z","dependencies_parsed_at":"2024-09-10T15:21:54.310Z","dependency_job_id":null,"html_url":"https://github.com/LucaPalminteri/mnist-digit-recognition-api","commit_stats":null,"previous_names":["lucapalminteri/mnist-digit-recognition-api"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/LucaPalminteri/mnist-digit-recognition-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LucaPalminteri%2Fmnist-digit-recognition-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LucaPalminteri%2Fmnist-digit-recognition-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LucaPalminteri%2Fmnist-digit-recognition-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LucaPalminteri%2Fmnist-digit-recognition-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LucaPalminteri","download_url":"https://codeload.github.com/LucaPalminteri/mnist-digit-recognition-api/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LucaPalminteri%2Fmnist-digit-recognition-api/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29332711,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-11T06:13:03.264Z","status":"ssl_error","status_checked_at":"2026-02-11T06:12:55.843Z","response_time":97,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","api-rest","fastapi","python"],"created_at":"2024-09-26T09:43:11.011Z","updated_at":"2026-02-11T12:01:47.911Z","avatar_url":"https://github.com/LucaPalminteri.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MNIST Model Training and Serving\n\nThis project demonstrates how to train a neural network model on the MNIST dataset and serve it using an API. The code is written in Python and utilizes packages like `torch`, `torchvision`, and `FastAPI`.\n\n## Features\n\n- **Training a Neural Network**: A Convolutional Neural Network (CNN) is used to classify MNIST digits.\n- **Model Persistence**: Save and load the trained model.\n- **API for Prediction**: A REST API built with FastAPI is used to serve the model for predictions on new data.\n- **Multiprocessing Support**: The Uvicorn server runs asynchronously to efficiently handle API requests.\n\n## Prerequisites\n\n- Python 3.11 or higher\n- pip (Python package manager)\n\n## Setup\n\n1. **Clone the repository**:\n\n    ```bash\n    git clone https://github.com/LucaPalminteri/mnist-digit-recognition-api\n    cd mnist-digit-recognition-api\n    ```\n\n2. **Install dependencies**:\n    Create and activate a virtual environment, and install the required packages:\n\n    ```bash\n    python -m venv .venv\n    source .venv/bin/activate  # On Windows: .venv\\Scripts\\activate\n    pip install -r requirements.txt\n    ```\n\n3. **Training the model**:\n    If you want to retrain the MNIST model, you can run the training script.\n\n    ```bash\n    python train.py\n    ```\n\n4. **Running the API**:\n    You can start the FastAPI server using Uvicorn:\n\n    ```bash\n    uvicorn main:app --reload\n    ```\n\n    The API will be available at `http://localhost:8000`.\n\n## Project Structure\n\n- **main.py**: Contains the FastAPI application and the logic for loading the model and making predictions.\n- **train.py**: Script for training the MNIST CNN model and saving the trained model.\n- **model.py**: Defines the MNIST model architecture.\n- **requirements.txt**: Lists all the Python dependencies needed to run the project.\n- **mnist.pth**: The trained model weights file.\n\n## API Endpoints\n\n- **POST /predict**: Takes an image (28x28 pixel array) and returns the predicted digit.\n\nExample request body:\n\n```json\n{\n  \"image\": [0, 1, 2, ..., 783]\n}\n```\n\nExample response:\n\n```json\n\n{   \n  \"predicted_digit\": 7 \n}\n```\n\n## Dependencies\n\nThe following Python packages are required for this project:\n\n- **torch**: For building and training the neural network.\n- **torchvision**: For datasets and model utilities.\n- **FastAPI**: For serving the trained model through an API.\n- **Uvicorn**: For running the FastAPI application.\n\n## Model Loading Warning\n\nWhen loading models with `torch.load()`, make sure to handle the security risks associated with untrusted sources. You should set `weights_only=True` to avoid loading unwanted code from pickled files.\n\n## Troubleshooting\n\n- **Deprecation warnings**: You may encounter warnings related to the use of deprecated arguments. Specifically:\n  - The `pretrained` argument is deprecated. Use `weights` instead.\n  - Use `torch.load(..., weights_only=True)` to avoid future security risks.\n- **Model loading errors**: If the model fails to load, ensure that the model architecture matches the saved state dictionary.\n\n## License\n\nThis project is licensed under the MIT License. See the LICENSE file for more details.\n\n### `requirements.txt`\n\n- torch\u003e=1.13.0\n- torchvision\u003e=0.14.0\n- fastapi\u003e=0.78.0\n- uvicorn\u003e=0.18.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucapalminteri%2Fmnist-digit-recognition-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucapalminteri%2Fmnist-digit-recognition-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucapalminteri%2Fmnist-digit-recognition-api/lists"}