Backend Documentation

Overview

This backend is a FastAPI-based application designed for object, expiry, and fruit/vegetable detection using advanced machine learning models.

Repository Link

You can find the repository on GitHub: Visit the Repository

Tech Stack

  • Framework: FastAPI
  • Machine Learning: Ultralytics YOLO
  • Computer Vision: OpenCV (cv2)
  • Deep Learning: PyTorch

Key Components

🤖 Machine Learning Models

Three specialized YOLO models are loaded for different detection tasks:

  • Object Detection Model: Identifies general product types
  • Expiry Detection Model: Detects expiry dates and labels
  • Fruit Detection Model: Identifies fruits and vegetables

🌐 WebSocket Endpoints

Real-time detection and streaming are managed through these WebSocket routes:

  • /ws/camera_feed_expiry: Object and expiry detection
  • /ws/camera_feed_fruit: Fruit and vegetable detection
  • /ws/fruits: Fruit detection data streaming

📦 Detection Workflow

  1. Frame received via WebSocket
  2. Image preprocessing
  3. Model inference
  4. Detection result visualization
  5. Result transmission back to client

Configuration Parameters

Parameter Description Default Value
obj_conf Object detection confidence threshold 0.5
expiry_conf Expiry detection confidence threshold 0.5
fruit_conf Fruit detection confidence threshold 0.5

Rest API Endpoints

Management Endpoints

  • GET /reset-detection: Reset detection parameters
  • GET /set-in-sensor: Toggle sensor state
  • GET /start-file-checker: Start background file processing
  • GET /stop-file-checker: Stop background file processing

Reporting Endpoints

  • POST /finish-task: Generate detection reports
  • GET /download-report: Download generated reports
  • POST /upload-data-video: Upload training/sample videos

Data Processing

The backend supports two primary detection modes:

  1. Packed Product Detection: Identifies product types and checks expiry
  2. Fruit/Vegetable Detection: Counts and categorizes produce

Performance Considerations

  • GPU-accelerated inference with CUDA
  • WebSocket for real-time communication
  • Buffering mechanisms to reduce processing overhead