# sua0649/reps_ai architecture

> Architecture diagram of the GitHub repository sua0649/reps_ai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sua0649/reps_ai
- Repository: https://github.com/sua0649/reps_ai

## Overview

1. Reps AI is a pose-analysis pipeline for workout form and rep counting. The repository is organized around a two-stage flow: video input is converted into body keypoints and engineered spatial features, then a temporal model or rule-based logic turns those sequences into rep/form outputs.

2. The main boundary is between raw motion data and model-ready artifacts. `data/processed/` contains the persisted outputs of preprocessing: per-exercise `.npy` arrays for keypoints/features and `.json` label files, plus a global `processing_summary.json` and `angle_names.json`. This is the handoff point from dataset preparation into model training and evaluation.

3. The spatial preprocessing subsystem lives in `cnn_module/`. `keypoint_extractor.py` wraps MediaPipe PoseLandmarker and produces 33 landmark skeletons from frames. `feature_engineer.py` transforms those landmarks into the repo’s compact feature representation, and `cnn_baseline.py` provides a spatial-only baseline for rep/form analysis.

4. `process_dataset.py` is the orchestration layer that builds the processed dataset from exercise videos. It drives extraction and labeling across exercises, producing the `data/processed/<exercise>/...` artifacts that downstream modules consume. This script is the clearest “ETL” boundary in the project.

5. The temporal modeling subsystem is in `lstm_module/`. `dataset.py` converts preprocessed sequences into sliding windows suitable for sequence learning; `model.py` defines the dual-head LSTM used for both rep count regression and form classification; `train.py` handles training and early stopping; `inference.py` runs standalone inference on video or sequence inputs.

6. Label generation is partially automated. `auto_labeler.py` indicates that temporal labels are derived from movement/state heuristics rather than fully manual annotation, which is important for the architecture: the system blends deterministic pose-state logic with learned sequence modeling instead of relying on a pure supervised video-labeling pipeline.

7. The integration layer in `integration/` is the runtime composition point. `real_time_system.py` is the live webcam/video application that connects capture, pose extraction, temporal inference, exercise-specific logic, and visualization. This is the module that should be treated as the end-user entry point for the architecture diagram.

8. Exercise-specific behavior is intentionally split inside the integrated runtime. The README and file names imply different decision logic per exercise: squat and push-up use LSTM plus angle/state-machine logic, pull-up uses dual-elbow averaging to stabilize rear-view detection, and plank is rule-based rather than learned because it is an isometric hold rather than a repetition sequence.

9. Evaluation is a separate concern from training and live inference. `integration/evaluate.py` compares CNN-only, LSTM-only, and combined approaches, while `evaluate_mpii.py`, `evaluate_coco.py`, and `evaluate_kaggle.py` adapt the pipeline to external benchmark formats. `analyze_dataset_labels.py` is a data-quality/label-distribution inspection tool.

10. The model and asset layer is split cleanly from code. `models/` stores the MediaPipe pose landmarker task files (`heavy`, `full`, `lite`) and trained model outputs such as `training_results.json` and, per the README, the trained LSTM weights. This makes the runtime dependent on external pose-estimation assets plus locally trained sequence models.

11. The external dependency with the biggest architectural impact is MediaPipe PoseLandmarker, downloaded from Google-hosted model URLs. It provides CPU-friendly pose estimation, which enables the real-time webcam path without requiring a dedicated GPU. The LSTM side implies a PyTorch-based training/inference stack.

12. `results/` and `training_log.txt` are output/reporting boundaries rather than core runtime components. They capture experiment summaries, benchmark results, and training history, supporting reproducibility and comparison without being part of the inference path.

13. Overall, the repository has three layers worth diagramming: preprocessing, sequence modeling, and integrated runtime. Data flows from video → pose landmarks → engineered features/windows → model or rules → rep count/form/timer overlays, with separate branches for offline dataset processing, training, and evaluation.

Main entry points: [`data/processed`](https://github.com/sua0649/reps_ai/tree/main/data/processed) (Processed data), [`integration/real_time_system.py`](https://github.com/sua0649/reps_ai/blob/main/integration/real_time_system.py) (Live system), [`lstm_module/model.py`](https://github.com/sua0649/reps_ai/blob/main/lstm_module/model.py) (LSTM model), [`results`](https://github.com/sua0649/reps_ai/tree/main/results) (Results)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_preprocessing["Preprocessing"]
  node_process_dataset["Process data<br/>etl script<br/>[process_dataset.py]"]
  node_keypoint_extractor["Keypoints<br/>pose extractor"]
  node_feature_engineer["Features"]
  node_auto_labeler["Auto label<br/>heuristic labeler<br/>[auto_labeler.py]"]
  node_cnn_baseline["CNN baseline<br/>spatial baseline<br/>[cnn_baseline.py]"]
end

subgraph group_sequence["Sequence Modeling"]
  node_window_dataset["Window data<br/>sequence dataset<br/>[dataset.py]"]
  node_lstm_model["LSTM model<br/>dual-head model<br/>[model.py]"]
  node_train["Train<br/>[train.py]"]
  node_inference["Infer<br/>[inference.py]"]
  node_baseline_lstm["LSTM-only<br/>baseline"]
end

subgraph group_runtime["Runtime & Evaluation"]
  node_real_time_system["Live system<br/>runtime app"]
  node_evaluate["Compare<br/>evaluation<br/>[evaluate.py]"]
  node_benchmark_adapters["Benchmarks<br/>adapters<br/>[evaluate_mpii.py]"]
  node_dataset_analysis["Label analysis<br/>inspection"]
end

subgraph group_assets["Models & Outputs"]
  node_processed_data[("Processed data<br/>artifact store")]
  node_pose_assets["Pose assets<br/>mediapipe models"]
  node_training_results["Results<br/>reports"]
end

node_process_dataset -->|"extract pose"| node_keypoint_extractor
node_process_dataset -->|"engineer features"| node_feature_engineer
node_process_dataset -->|"derive labels"| node_auto_labeler
node_keypoint_extractor -->|"write keypoints"| node_processed_data
node_feature_engineer -->|"write features"| node_processed_data
node_auto_labeler -->|"write labels"| node_processed_data
node_processed_data -->|"load sequences"| node_window_dataset
node_window_dataset -->|"feed windows"| node_lstm_model
node_lstm_model -->|"optimize"| node_train
node_train -->|"save metrics"| node_training_results
node_processed_data -->|"load inputs"| node_inference
node_lstm_model -->|"predict"| node_inference
node_processed_data -->|"baseline input"| node_cnn_baseline
node_pose_assets -->|"pose model"| node_real_time_system
node_real_time_system -.->|"runtime handoff"| node_processed_data
node_real_time_system -->|"temporal inference"| node_lstm_model
node_real_time_system -.->|"spatial fallback"| node_cnn_baseline
node_real_time_system -.->|"log output"| node_training_results
node_evaluate -->|"compare sequence"| node_baseline_lstm
node_evaluate -->|"compare spatial"| node_cnn_baseline
node_evaluate -->|"store comparisons"| node_training_results
node_benchmark_adapters -->|"benchmark reports"| node_training_results
node_dataset_analysis -.->|"inspect labels"| node_processed_data

click node_process_dataset "https://github.com/sua0649/reps_ai/blob/main/process_dataset.py"
click node_keypoint_extractor "https://github.com/sua0649/reps_ai/blob/main/cnn_module/keypoint_extractor.py"
click node_feature_engineer "https://github.com/sua0649/reps_ai/blob/main/cnn_module/feature_engineer.py"
click node_auto_labeler "https://github.com/sua0649/reps_ai/blob/main/lstm_module/auto_labeler.py"
click node_cnn_baseline "https://github.com/sua0649/reps_ai/blob/main/cnn_module/cnn_baseline.py"
click node_processed_data "https://github.com/sua0649/reps_ai/tree/main/data/processed"
click node_window_dataset "https://github.com/sua0649/reps_ai/blob/main/lstm_module/dataset.py"
click node_lstm_model "https://github.com/sua0649/reps_ai/blob/main/lstm_module/model.py"
click node_train "https://github.com/sua0649/reps_ai/blob/main/lstm_module/train.py"
click node_inference "https://github.com/sua0649/reps_ai/blob/main/lstm_module/inference.py"
click node_baseline_lstm "https://github.com/sua0649/reps_ai/blob/main/lstm_module/baseline_lstm_only.py"
click node_real_time_system "https://github.com/sua0649/reps_ai/blob/main/integration/real_time_system.py"
click node_evaluate "https://github.com/sua0649/reps_ai/blob/main/integration/evaluate.py"
click node_benchmark_adapters "https://github.com/sua0649/reps_ai/blob/main/integration/evaluate_mpii.py"
click node_dataset_analysis "https://github.com/sua0649/reps_ai/blob/main/integration/analyze_dataset_labels.py"
click node_pose_assets "https://github.com/sua0649/reps_ai/tree/main/models"
click node_training_results "https://github.com/sua0649/reps_ai/tree/main/results"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_process_dataset,node_keypoint_extractor,node_feature_engineer,node_auto_labeler,node_cnn_baseline toneBlue
class node_window_dataset,node_lstm_model,node_train,node_inference,node_baseline_lstm toneAmber
class node_real_time_system,node_evaluate,node_benchmark_adapters,node_dataset_analysis toneMint
class node_processed_data,node_pose_assets,node_training_results toneRose
```

## Components

### Preprocessing

Video-to-artifact ETL, pose extraction, feature engineering, and label generation.

- [Process data](https://github.com/sua0649/reps_ai/blob/main/process_dataset.py): etl script · Builds the processed exercise dataset from raw videos and labels. · `process_dataset.py`
- [Keypoints](https://github.com/sua0649/reps_ai/blob/main/cnn_module/keypoint_extractor.py): pose extractor · Wraps MediaPipe PoseLandmarker to produce 33-landmark skeletons from frames. · `cnn_module/keypoint_extractor.py`
- [Features](https://github.com/sua0649/reps_ai/blob/main/cnn_module/feature_engineer.py): spatial features · Converts keypoints into compact engineered pose features. · `cnn_module/feature_engineer.py`
- [Auto label](https://github.com/sua0649/reps_ai/blob/main/lstm_module/auto_labeler.py): heuristic labeler · Derives temporal labels from movement and pose-state heuristics. · `lstm_module/auto_labeler.py`
- [CNN baseline](https://github.com/sua0649/reps_ai/blob/main/cnn_module/cnn_baseline.py): spatial baseline · Spatial-only baseline for rep counting and form analysis. · `cnn_module/cnn_baseline.py`

### Sequence Modeling

Sliding-window dataset preparation, LSTM training, and inference on temporal pose sequences.

- [Window data](https://github.com/sua0649/reps_ai/blob/main/lstm_module/dataset.py): sequence dataset · Turns preprocessed sequences into sliding windows for sequence learning. · `lstm_module/dataset.py`
- [LSTM model](https://github.com/sua0649/reps_ai/blob/main/lstm_module/model.py): dual-head model · Predicts rep count and form classification from temporal windows. · `lstm_module/model.py`
- [Train](https://github.com/sua0649/reps_ai/blob/main/lstm_module/train.py): trainer · Handles training loop, validation, and early stopping. · `lstm_module/train.py`
- [Infer](https://github.com/sua0649/reps_ai/blob/main/lstm_module/inference.py): sequence inference · Runs standalone inference on videos or precomputed sequences. · `lstm_module/inference.py`
- [LSTM-only](https://github.com/sua0649/reps_ai/blob/main/lstm_module/baseline_lstm_only.py): baseline · Sequence-only baseline used for comparison against the integrated pipeline. · `lstm_module/baseline_lstm_only.py`

### Runtime & Evaluation

Live application, benchmark adapters, and experiment reporting.

- [Live system](https://github.com/sua0649/reps_ai/blob/main/integration/real_time_system.py): runtime app · Connects capture, pose extraction, inference, exercise logic, and visualization. · `integration/real_time_system.py`
- [Compare](https://github.com/sua0649/reps_ai/blob/main/integration/evaluate.py): evaluation · Compares CNN-only, LSTM-only, and combined approaches. · `integration/evaluate.py`
- [Benchmarks](https://github.com/sua0649/reps_ai/blob/main/integration/evaluate_mpii.py): adapters · Adapts the pipeline to MPII, COCO, and Kaggle evaluation formats. · `integration/evaluate_mpii.py`
- [Label analysis](https://github.com/sua0649/reps_ai/blob/main/integration/analyze_dataset_labels.py): inspection · Inspects dataset labels and distribution quality. · `integration/analyze_dataset_labels.py`

### Models & Outputs

External pose assets, processed datasets, and persisted results.

- [Processed data](https://github.com/sua0649/reps_ai/tree/main/data/processed): artifact store · Persisted per-exercise keypoints, features, labels, and summaries under data/processed/. · `data/processed`
- [Pose assets](https://github.com/sua0649/reps_ai/tree/main/models): mediapipe models · MediaPipe PoseLandmarker task files used for CPU-friendly pose estimation. · `models`
- [Results](https://github.com/sua0649/reps_ai/tree/main/results): reports · Persisted training results, benchmark outputs, and experiment summaries. · `results`

## Connections

- Process data → Keypoints: extract pose · Frames are converted into landmark skeletons.
- Process data → Features: engineer features · Keypoints are transformed into spatial feature arrays.
- Process data → Auto label: derive labels · Heuristic logic produces temporal labels.
- Keypoints → Processed data: write keypoints · Persist extracted landmarks per exercise.
- Features → Processed data: write features · Persist engineered arrays for downstream use.
- Auto label → Processed data: write labels · Persist sequence labels and summaries.
- Processed data → Window data: load sequences · Training and inference consume processed artifacts.
- Window data → LSTM model: feed windows · Sliding windows are used as model inputs.
- LSTM model → Train: optimize · Training updates the temporal model.
- Train → Results: save metrics · Training outputs are stored for comparison.
- Processed data → Infer: load inputs · Inference can start from processed sequences or videos.
- LSTM model → Infer: predict · Model outputs rep and form predictions.
- Processed data → CNN baseline: baseline input · Spatial baseline consumes processed pose artifacts.
- Pose assets → Live system: pose model · Live runtime depends on MediaPipe pose assets.
- Live system → Processed data: runtime handoff · Live path reuses the same pose/feature boundary when applicable.
- Live system → LSTM model: temporal inference · Integrated runtime uses the sequence model for rep/form decisions.
- Live system → CNN baseline: spatial fallback · Spatial baseline contributes to combined comparisons and exercise logic.
- Live system → Results: log output · Live application and experiments surface results and histories.
- Compare → LSTM-only: compare sequence · Evaluation includes LSTM-only comparisons.
- Compare → CNN baseline: compare spatial · Evaluation includes CNN-only comparisons.
- Compare → Results: store comparisons · Comparison results are persisted.
- Benchmarks → Results: benchmark reports · External benchmark runs are collected as output artifacts.
- Label analysis → Processed data: inspect labels · Analysis reads processed labels for quality checks.
