Skip to content

A-Ahmed-I/Dockerize-Model

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dockerize-Model

Overview

Dockerize-Model is an end-to-end, Docker-ready deep learning project that classifies fresh vs. rotten fruits (peaches, pomegranates, strawberries). The repository includes data processing utilities, model training code, a FastAPI inference service, and Docker configuration for reproducible deployment.


Table of Contents

  • Features
  • Quick Start
  • Local Development
  • Docker Deployment
  • API Reference (examples)
  • Configuration
  • Project Structure
  • Notes: Model & Data
  • Contributing
  • License

Features

  • Image classification for multiple fruit types (fresh/rotten)
  • Modular and well-organized code (data, models, api, utils)
  • FastAPI REST service for inference
  • Dockerfile for consistent deployment
  • Logging and configuration via src/constants/constants.py

Quick Start (Docker) — recommended

  1. Build the Docker image:
docker build -t dockerize-model .
  1. Run the container and expose the API:
docker run -it -p 5000:5000 dockerize-model
  1. Visit the interactive API docs: http://localhost:5000/docs

Local Development (Python)

  1. Create and activate a virtual environment (recommended):
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
  1. Run the FastAPI app locally:
python src/api/main.py
  1. Open the API docs: http://localhost:5000/docs

API Reference

Predict endpoint:

  • POST /predict
    • Accepts: multipart/form-data with a file field named file
    • Returns: JSON with FileName, PredictionClass, and prediction (confidence)

Example curl request:

curl -X POST "http://localhost:5000/predict" -F "file=@/path/to/image.jpg"

Example Python client (requests):

import requests

url = "http://localhost:5000/predict"
with open("/path/to/image.jpg", "rb") as f:
    r = requests.post(url, files={"file": f})
print(r.json())

Sample response:

{
  "FileName": "strawberry.jpg",
  "PredictionClass": "Fresh Strawberries",
  "prediction": 0.9876
}

Configuration

  • Most runtime/configuration values live in src/constants/constants.py (e.g., MODEL_PATH, HOST, PORT, and RESIZE).
  • Make sure the model file is available at models/checkpoints/model.keras or update MODEL_PATH.

Note: The README previously referenced src/constant/constant.py. The correct path is src/constants/constants.py.


Project Structure

Dockerize-Model
├── Dockerfile
├── README.md
├── requirements.txt
├── src/
│   ├── api/           # FastAPI app, endpoints and schemas
│   ├── constants/     # Paths and configuration
│   ├── data/          # Data ingestion/processing helpers
│   ├── models/        # Model definition / training utilities
│   └── utils/         # Helpers (e.g., model loading)
├── data/
│   ├── raw/
│   └── processed/
├── models/
│   └── checkpoints/   # Place `model.keras` here
├── notebooks/         # EDA and experiments
└── logs/

Model & Data Notes

  • Pretrained model: models/checkpoints/model.keras (expected by default). If not present, inference will fail when loading the model — see logs for details.
  • Data files used for experiments are in data/processed/*.json (train/test splits).

Troubleshooting & Tips

  • If server fails to start, check MODEL_PATH and ensure the model file exists.
  • Validate image uploads via the /docs UI to see expected request shape.
  • Logs are written to the logs/ directory (see LOG_FILE and LOG_DIR in src/constants/constants.py).

Contributing

Contributions, bug reports, and improvements are welcome. Please open an issue or submit a pull request.


License

This project is licensed under the MIT License — see the LICENSE file.

About

Deep learning project for fruit classification with FastAPI REST API, modular code, and Docker deployment.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors