# adityasarsenal/yoga_trainer architecture

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

- Interactive diagram: https://gitdiagram.com/adityasarsenal/yoga_trainer
- Repository: https://github.com/adityasarsenal/yoga_trainer

## Overview

##### Main Components
- Inference/Live Yoga Trainer:
- Main Execution: The src/main.py file is the entry point for the yoga trainer. Other “main” scripts (e.g., downdog_main.py, goddess_main.py, warrior2_main.py) handle specialized yoga poses.
- Pose Detection: These components include both the MediaPipe-based detection as well as the fine-tuned MobileNetV2 model (loaded via live_cam_test.py).
- Voice Instruction Module: The auio_conv.py script integrates a text-to-speech model (pyttsx3), connecting detected pose outcomes with vocal instructions.
- Pose Checking Utilities: Files such as downdog_checks.py, goddness_checks.py, tree_checks.py, and worrior2_checks.py are used to verify the correctness of the pose.

- Training Pipeline:
- Data Processing: The train_n_test folder contains scripts for data sampling (_data_sampling.py), pre-processing (_pre_processing_data.py), and synthetic data generation (_synthatic_data_prodection.py), which prepare the dataset for fine-tuning.
- Fine-Tuning Steps: There are components dedicated to model training (_fine_tuneing.py), evaluation (_pre_train_eval.py), and post-training testing (_fine_tuned_model_testing.py and _sample_test_after_finetuned.py).
- Model Saving: The fine-tuned MobileNetV2 results in a saved .h5 model that is later loaded for inference.

##### Relationships and Interactions
- The Inference Module:
- The live_cam_test.py script loads the fine-tuned model (.h5) and uses the webcam feed to detect current yoga poses.
- Once a pose is detected, control flows to the corresponding “main” script (e.g., goddess_main.py for the goddess pose) which then calls on its paired “checks” script and ultimately invokes the auio_conv.py module to provide voice feedback.
- Directional flow: webcam feed → pose detection (MobileNetV2 & MediaPipe) → specific pose module → voice instruction.

- The Training Module:
- The pipeline begins with data ingestion and sampling. If the dataset is insufficient, synthetic augmentation is performed.
- The data then moves through pre-processing, after which fine-tuning is applied to MobileNetV2 for gesture recognition.
- The trained model is persisted as a .h5 file and later used by the inference module.

##### Architectural Patterns and Design Principles
- Modularity: The project is segregated into distinct modules or layers—separate scripts handling different poses and a dedicated training pipeline. This modularity makes it easier to scale or replace components.
- Reusability: The use of common utility scripts (e.g., for data sampling and voice instructions) helps in reusing code across both inference and training components.
- Clear Separation of Concerns: The inference layer (real-time pose detection and instruction) is clearly separated from the training pipeline (data preparation and model fine tuning).

##### Relevant Technologies and Frameworks
- Deep Learning: The fine-tuned MobileNetV2 model backbone.
- Computer Vision: MediaPipe for pose estimation.
- Text-to-Speech: The use of pyttsx3 in auio_conv.py.
- Data Processing: Python scripts for data sampling, pre-processing, and synthetic data generation.
- Environment & Dependencies: The README specifies dependency on Python 3.10.11 and specific library versions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Inference Layer (Yoga Trainer)
    subgraph "Inference Layer (Yoga Trainer)"
        direction TB
        A["src/live_cam_test.py"]:::inference
        B["src/main.py"]:::inference
        G["src/pose.py"]:::inference
        C["src/downdog_main.py"]:::inference
        D["src/goddess_main.py"]:::inference
        E["src/tree_main.py"]:::inference
        F["src/warrior2_main.py"]:::inference
        C1["src/downdog_checks.py"]:::utility
        D1["src/godness_checks.py"]:::utility
        E1["src/tree_checks.py"]:::utility
        F1["src/worrior2_checks.py"]:::utility
        X["src/auio_conv.py"]:::inference

        %% Inference Flow
        A --> B
        A --> G
        B --> C
        B --> D
        B --> E
        B --> F

        C --> C1
        D --> D1
        E --> E1
        F --> F1

        C1 --> X
        D1 --> X
        E1 --> X
        F1 --> X
    end

    %% Training Pipeline
    subgraph "Training Pipeline"
        direction TB
        T1["train_n_test/_data_sampling.py"]:::training
        T2["train_n_test/_pre_processing_data.py"]:::training
        T3["train_n_test/_synthatic_data_prodection.py"]:::training
        T4["train_n_test/_fine_tuneing.py"]:::training
        T5["train_n_test/_pre_train_eval.py"]:::training
        T6["train_n_test/_fine_tuned_model_testing.py"]:::training
        T7["train_n_test/_sample_test_after_finetuned.py"]:::training
        T8["Saved Model (.h5)"]:::training
        T9["train_n_test/_classifier_load.py"]:::training

        T1 --> T2
        T2 --> T3
        T3 --> T4
        T4 --> T5
        T5 --> T6
        T6 --> T7
        T7 --> T8
        T8 --> T9
    end

    %% Connection from Training Pipeline to Inference Layer
    T9 --> A

    %% Styles
    classDef inference fill:#AED6F1,stroke:#3498DB,stroke-width:2px;
    classDef training fill:#A9DFBF,stroke:#28B463,stroke-width:2px;
    classDef utility fill:#F9E79F,stroke:#F1C40F,stroke-width:2px;

    %% Click Events
    click B "https://github.com/adityasarsenal/yoga_trainer/blob/main/src/main.py"
    click C "https://github.com/adityasarsenal/yoga_trainer/blob/main/src/downdog_main.py"
    click D "https://github.com/adityasarsenal/yoga_trainer/blob/main/src/goddess_main.py"
    click E "https://github.com/adityasarsenal/yoga_trainer/blob/main/src/tree_main.py"
    click F "https://github.com/adityasarsenal/yoga_trainer/blob/main/src/warrior2_main.py"
    click A "https://github.com/adityasarsenal/yoga_trainer/blob/main/src/live_cam_test.py"
    click G "https://github.com/adityasarsenal/yoga_trainer/blob/main/src/pose.py"
    click X "https://github.com/adityasarsenal/yoga_trainer/blob/main/src/auio_conv.py"
    click C1 "https://github.com/adityasarsenal/yoga_trainer/blob/main/src/downdog_checks.py"
    click D1 "https://github.com/adityasarsenal/yoga_trainer/blob/main/src/godness_checks.py"
    click E1 "https://github.com/adityasarsenal/yoga_trainer/blob/main/src/tree_checks.py"
    click F1 "https://github.com/adityasarsenal/yoga_trainer/blob/main/src/worrior2_checks.py"
    click T1 "https://github.com/adityasarsenal/yoga_trainer/blob/main/train_n_test/_data_sampling.py"
    click T2 "https://github.com/adityasarsenal/yoga_trainer/blob/main/train_n_test/_pre_processing_data.py"
    click T3 "https://github.com/adityasarsenal/yoga_trainer/blob/main/train_n_test/_synthatic_data_prodection.py"
    click T4 "https://github.com/adityasarsenal/yoga_trainer/blob/main/train_n_test/_fine_tuneing.py"
    click T5 "https://github.com/adityasarsenal/yoga_trainer/blob/main/train_n_test/_pre_train_eval.py"
    click T6 "https://github.com/adityasarsenal/yoga_trainer/blob/main/train_n_test/_fine_tuned_model_testing.py"
    click T7 "https://github.com/adityasarsenal/yoga_trainer/blob/main/train_n_test/_sample_test_after_finetuned.py"
    click T9 "https://github.com/adityasarsenal/yoga_trainer/blob/main/train_n_test/_classifier_load.py"
```
