How sua0649/reps_ai works
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: processed Processed data · real_time_system.py Live system · model.py LSTM model · results Results
Components 17
Preprocessing
Video-to-artifact ETL, pose extraction, feature engineering, and label generation.
- Process data · Builds the processed exercise dataset from raw videos and labels.
process_dataset.py - Keypoints · Wraps MediaPipe PoseLandmarker to produce 33-landmark skeletons from frames.
cnn_module/keypoint_extractor.py - Features · Converts keypoints into compact engineered pose features.
cnn_module/feature_engineer.py - Auto label · Derives temporal labels from movement and pose-state heuristics.
lstm_module/auto_labeler.py - CNN 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 · Turns preprocessed sequences into sliding windows for sequence learning.
lstm_module/dataset.py - LSTM model · Predicts rep count and form classification from temporal windows.
lstm_module/model.py - Train · Handles training loop, validation, and early stopping.
lstm_module/train.py - Infer · Runs standalone inference on videos or precomputed sequences.
lstm_module/inference.py - LSTM-only · 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 · Connects capture, pose extraction, inference, exercise logic, and visualization.
integration/real_time_system.py - Compare · Compares CNN-only, LSTM-only, and combined approaches.
integration/evaluate.py - Benchmarks · Adapts the pipeline to MPII, COCO, and Kaggle evaluation formats.
integration/evaluate_mpii.py - Label analysis · Inspects dataset labels and distribution quality.
integration/analyze_dataset_labels.py
Models & Outputs
External pose assets, processed datasets, and persisted results.
- Processed data · Persisted per-exercise keypoints, features, labels, and summaries under data/processed/.
data/processed - Pose assets · MediaPipe PoseLandmarker task files used for CPU-friendly pose estimation.
models - Results · Persisted training results, benchmark outputs, and experiment summaries.
results
Connections 23
- 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.