# saideva9826/yolo architecture

> Architecture diagram of the GitHub repository saideva9826/yolo, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/saideva9826/yolo
- Repository: https://github.com/saideva9826/yolo

## Overview

##### Project Type and Purpose
- This is a full-stack Computer Vision application built around YOLO object detection.
- It covers model training/optimization, a prediction API (Flask + AWS Lambda), and a minimal web UI for demoing results.

##### File Structure
- Top-level files
- main.py, yolo.py, yolo_to_json_converter.py – core Python scripts for training, inference, and output conversion
- deploy_lambda.sh, lambda_requirements.txt – deployment scripts for AWS Lambda
- test_payload.json – sample input for serverless function
- app/
- app/main.py – entry point for on-premise or local inference/training
- app/lambda_yolo_function.py – handler for AWS Lambda inference
- notebooks/
- Research, tutorials, and markdowns documenting every stage (YOLO intro, transfer learning, deployment)
- static/ & templates/
- templates/index.html – minimal web front-end
- zips & PPTX
- yolo_flask_api_src.zip – packaged Flask API source
- “Computer Vision with YOLO…” – slide deck

##### README
- Confirms four main features: YOLO training, Flask API, AWS Lambda deployment, transfer learning
- Mentions the high-level folder layout

##### Main Components
a. Model Training & Optimization Layer
– “main.py” orchestrates data loading, model compilation, transfer-learning, and weight export
– Jupyter notebooks feed into your experimentation cycle
b. Conversion Layer
– “yolo_to_json_converter.py” transforms raw YOLO outputs into JSON payloads
c. Inference Services
1. Local/Premise Flask API
- Runs app/main.py or packaged code from yolo_flask_api_src.zip
- Exposes HTTP endpoint `POST /detect`
- Serves static results and index.html for demo
2. AWS Lambda Serverless Function
- `app/lambda_yolo_function.py` triggered via API Gateway or CLI
- Receives base64-encoded image, runs YOLO inference, returns JSON
d. Frontend Layer
– index.html + static assets request detection from either local API or Lambda endpoint
e. External Services (optional)
– S3 or other storage for persisting models or storing payloads
– CloudWatch for Lambda logs

##### Relationships & Data Flows
- Training → exported model weights → (a) Conversion & packaging for Lambda, (b) local Flask container
- Client (browser) → HTTP → Flask API or API Gateway → Lambda function
- Inference results → JSON → converter (if needed) → returned to client → overlay on static image

##### Architectural Patterns & Principles
- Separation of Concerns: distinct modules for training, conversion, inference, and presentation
- Microservices/Serverless: local Flask vs. AWS Lambda interchangeable inference endpoints
- MVC-lite: index.html (View) ↔ Flask routes or Lambda (Controller) ↔ YOLO model (Model)

##### Detail
- Script or directory as a component.
- How notebooks feed into main.py and how weights propagate to both local and serverless stacks.
- External integrations (API Gateway, S3) if used or planned.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Training & Experimentation" 
        TR_Notebooks["notebooks/"]:::compute
        TR_YoloScript["yolo.py"]:::compute
        TR_AppMain["app/main.py"]:::compute
    end

    ModelWeights["Model Weights (.pt/.h5)"]:::data

    subgraph "Conversion Layer"
        Converter["yolo_to_json_converter.py"]:::compute
    end

    JSONPayload["JSON Payload"]:::data

    subgraph "Inference Services"
        subgraph "Local Flask API"
            LF_Zip["yolo_flask_api_src.zip"]:::compute
            LF_Static["static/"]:::ui
            LF_Index["templates/index.html"]:::ui
        end
        subgraph "AWS Lambda Function"
            LA_Func["app/lambda_yolo_function.py"]:::compute
            LA_Deploy["deploy_lambda.sh"]:::compute
            LA_Req["lambda_requirements.txt"]:::compute
            LA_Test["test_payload.json"]:::data
        end
    end

    subgraph "Presentation Layer"
        Browser["Client Browser"]:::external
        UI_Index["templates/index.html"]:::ui
        UI_Static["static/"]:::ui
    end

    subgraph "External Services"
        APIGW["API Gateway"]:::external
        S3["S3 Storage"]:::external
        CW["CloudWatch"]:::external
    end

    TR_Notebooks -->|experimentation| TR_YoloScript
    TR_Notebooks -->|experimentation| TR_AppMain
    TR_YoloScript -->|produces| ModelWeights
    TR_AppMain -->|produces| ModelWeights

    ModelWeights -->|feeds into| Converter
    Converter -->|outputs| JSONPayload

    ModelWeights -->|packaged for| LF_Zip
    ModelWeights -->|packaged for| LA_Deploy

    Browser -->|HTTP POST /detect| ServiceLocal[("Local Flask Endpoint")]:::external
    ServiceLocal --> LF_Zip
    ServiceLocal -->|loads weights & runs| TR_AppMain
    ServiceLocal --> Converter
    Converter -->|returns| JSONPayload
    JSONPayload --> Browser

    Browser -->|HTTP POST| APIGW
    APIGW --> ServiceLambda[("Lambda Endpoint")]:::external
    ServiceLambda --> LA_Func
    ServiceLambda -->|loads weights & runs| LA_Func
    ServiceLambda --> Converter
    Converter -->|returns| JSONPayload
    JSONPayload --> Browser
    APIGW --> CW
    LA_Func --> CW
    LA_Func --> S3

    Browser --> UI_Index
    UI_Index --> UI_Static

    classDef compute fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef data fill:#90EE90,stroke:#333,stroke-width:1px
    classDef ui fill:#FFFF99,stroke:#333,stroke-width:1px
    classDef external fill:#f0f0f0,stroke:#333,stroke-width:1px

    click TR_Notebooks "https://github.com/saideva9826/yolo/tree/master/notebooks/"
    click TR_YoloScript "https://github.com/saideva9826/yolo/blob/master/yolo.py"
    click TR_AppMain "https://github.com/saideva9826/yolo/blob/master/app/main.py"
    click Converter "https://github.com/saideva9826/yolo/blob/master/yolo_to_json_converter.py"
    click LF_Zip "https://github.com/saideva9826/yolo/blob/master/yolo_flask_api_src.zip"
    click LF_Static "https://github.com/saideva9826/yolo/tree/master/static/"
    click LF_Index "https://github.com/saideva9826/yolo/blob/master/templates/index.html"
    click LA_Func "https://github.com/saideva9826/yolo/blob/master/app/lambda_yolo_function.py"
    click LA_Deploy "https://github.com/saideva9826/yolo/blob/master/deploy_lambda.sh"
    click LA_Req "https://github.com/saideva9826/yolo/blob/master/lambda_requirements.txt"
    click LA_Test "https://github.com/saideva9826/yolo/blob/master/test_payload.json"
    click UI_Index "https://github.com/saideva9826/yolo/blob/master/templates/index.html"
    click UI_Static "https://github.com/saideva9826/yolo/tree/master/static/"
```
