This project provides a FastAPI-based backend application for object detection, expiry detection, and fruit/vegetable classification using YOLO models. The application includes WebSocket endpoints for real-time detection and image processing and REST APIs for additional operations.
- Object detection for identifying products.
- Expiry detection for recognizing and saving expiration details.
- Fruit and vegetable classification with tracking capabilities.
- WebSocket endpoints for real-time video feed processing.
- Integration with YOLO models for high-performance inference.
- Configurable confidence thresholds for detection models.
- Python 3.8 or later.
- GPU with CUDA support (recommended for better performance).
- Installed
venvfor virtual environment management. - Installed ultralytics library for YOLO.
-
Clone this repository:
git clone <repository-url> cd <repository-folder>
-
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
now install torch with CUDA
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
now create a .env file with the field
gemini_key=<api-key-here>
-
Place your YOLO models in the
model/directory:object_detection.ptexpiry.ptfruit.pt
-
Run the application:
uvicorn main:app --reload
- Processes real-time video feed for packed product object and expiry detection.
- Input: Base64-encoded image frames.
- Output: Annotated frames with detected objects/expiry details.
- Provides real-time updates on detected expiry details.
- Processes real-time video feed for fruit/vegetable detection.
- Input: Base64-encoded image frames.
- Output: Annotated frames with detected fruits/vegetables.
- Provides real-time updates on detected fruit/vegetable counts.
- Modify confidence thresholds for models in the script:
obj_conf = 0.5 expiry_conf = 0.5 fruit_conf = 0.5
├── reports
├── VIDEO_UPLOADS
├── details
├── data
|
├── model
│ ├── object_detection.pt
│ ├── expiry.pt
│ └── fruit.pt
├── utils
│ ├── image_process.py
│ ├── gemini_image.py
│ ├── handlelist.py
│ ├── handlereports.py
│ └── handleuploads.py
|
├── file_checker.py
├── main.py
├── requirements.txt
└── README.md
The utils directory contains helper scripts:
image_process.py: For processing and saving images.handlelist.py: Manages lists and JSON operations.handlereports.py: Handles report generation in Excel format.handleuploads.py: Processes uploaded files.
- Ensure that
file_checker.pyexists in the root directory for background file-checking functionality.