# mohammad-oghli/yolo-animal-classify architecture

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

- Interactive diagram: https://gitdiagram.com/mohammad-oghli/yolo-animal-classify
- Repository: https://github.com/mohammad-oghli/yolo-animal-classify

## Overview

##### Project type and purpose
- From the README and file tree, this is an image-processing inference application (not a full frontend/back-end web app) that uses two pre-trained Ultralytics YOLOv11 models to (1) detect a single animal in an image, then (2) classify which animal it is.
- Key components: a simple API/CLI entry point (`app.py`), a model module (`model.py`), helper routines (`helper.py`), two model artifacts (`.pt` files in `YOLO_models/`), and an example Jupyter notebook for demonstration.

##### File structure
- Top level:
- `app.py` – the main application script or REST endpoint handler
- `model.py` – defines `detection_model()` and `classify_model()`
- `YOLO_models/` – hosts the two pre-trained model files (`yolo11n.pt`, `yolo11n-cls.pt`)
- `classify_notebook.ipynb` – usage example
- `requirements*.txt` – Python dependencies
- No database or message‐broker directories—this is a single‐process inference service.

##### README for additional insights
- Workflow:
2. Crop the detected region and feed it to `yolo11n-cls` for classification
- No mention of web frontend beyond `app.py` (likely a Flask/FastAPI endpoint or CLI).

##### Main components & interactions
a. Components
- Client (could be a REST client, CLI user, or notebook)
- API/Controller (`app.py`)
- Detection Service (`model.detection_model`)
- Classification Service (`model.classify_model`)
- Helper/Visualization Module (`helper.py`)
- Model Storage (local filesystem under `YOLO_models/`)
- External Libraries (PyTorch, Ultralytics YOLO, OpenCV/PIL)
b. Relationships & data flow
1. Client → (HTTP POST or function call) → API/Controller
2. API reads image → passes to Detection Service
4. API crops the image region → sends to Classification Service
5. Classification Service loads `yolo11n-cls.pt` → returns class label + confidence
c. Architectural patterns
- Pipeline pattern (sequential detection → classification)
- Modular layering (API layer → service layer → data/model layer)
d. Technologies & frameworks
- Python 3.x, Ultralytics YOLO via PyTorch
- OpenCV / PIL for image operations
- (Optional) Flask or FastAPI if `app.py` exposes HTTP endpoints

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients and Examples
    Client["Client\n(REST/CLI)"]:::client
    Notebook["Jupyter Notebook\n(classify_notebook.ipynb)"]:::file
    Images["Image Samples\n(images/)"]:::file
    ReqDev["requirements.txt"]:::file
    ReqProd["requirements-prod.txt"]:::file

    %% Inference Service
    subgraph "Inference Service"
        API["API/Controller\n(app.py)"]:::api
        DS["Detection Service\n(model.detection_model)"]:::service
        CS["Classification Service\n(model.classify_model)"]:::service
        Helper["Helper/Visualization\n(helper.py)"]:::helper
    end

    %% Model Storage
    subgraph "Model Storage"
        Y1["yolo11n.pt"]:::file
        Y2["yolo11n-cls.pt"]:::file
    end

    %% External Dependencies
    External["External Libraries\n(PyTorch, Ultralytics YOLO,\nOpenCV/PIL)"]:::external

    %% Data Flows
    Client -->|"Image"| API
    Notebook -->|"Image"| API
    API -->|"Image"| DS
    DS -->|"Bounding Box"| API
    API -->|"Cropped ROI"| CS
    CS -->|"Class & Confidence"| API
    API -->|"draw box & label"| Helper
    Helper -->|"Annotated Image/JSON"| API
    API -->|"Response"| Client

    %% Model Loading
    DS --"load weights"--> Y1
    CS --"load weights"--> Y2

    %% Dependencies
    API --> External
    DS --> External
    CS --> External
    Helper --> External

    %% File References
    click API "https://github.com/mohammad-oghli/yolo-animal-classify/blob/main/app.py"
    click DS "https://github.com/mohammad-oghli/yolo-animal-classify/blob/main/model.py"
    click CS "https://github.com/mohammad-oghli/yolo-animal-classify/blob/main/model.py"
    click Helper "https://github.com/mohammad-oghli/yolo-animal-classify/blob/main/helper.py"
    click Y1 "https://github.com/mohammad-oghli/yolo-animal-classify/blob/main/YOLO_models/yolo11n.pt"
    click Y2 "https://github.com/mohammad-oghli/yolo-animal-classify/blob/main/YOLO_models/yolo11n-cls.pt"
    click Notebook "https://github.com/mohammad-oghli/yolo-animal-classify/blob/main/classify_notebook.ipynb"
    click Images "https://github.com/mohammad-oghli/yolo-animal-classify/tree/main/images/"
    click ReqDev "https://github.com/mohammad-oghli/yolo-animal-classify/blob/main/requirements.txt"
    click ReqProd "https://github.com/mohammad-oghli/yolo-animal-classify/blob/main/requirements-prod.txt"

    %% Styles
    classDef client fill:#fff9c4,stroke:#333,stroke-width:1px
    classDef api fill:#bbdefb,stroke:#333,stroke-width:1px
    classDef service fill:#90caf9,stroke:#333,stroke-width:1px
    classDef helper fill:#ffe082,stroke:#333,stroke-width:1px
    classDef file fill:#e1bee7,stroke:#333,stroke-width:1px
    classDef external fill:#c5e1a5,stroke:#333,stroke-width:1px
```
