How eliaslozadam/proyect_adapt-ecg works
1. Overall system shape
ADAPT-ECG is a research-oriented ECG classification platform built around a 1D CNN in PyTorch plus a continual re-training loop. The repo is organized as a pipeline: external ECG data comes in, signals are preprocessed, the model predicts arrhythmia classes, and later retraining updates the model using a replay buffer to reduce forgetting.
2. External data boundary
The primary external dependency is the MIT-BIH Arrhythmia Database from PhysioNet. The repository treats this as the canonical source of ECG signals and annotations. This is the main ingress boundary between the project and the outside world.
3. Data ingestion and preprocessing
The runtime data layer lives in src/data/:
- ingest.py handles loading/reading ECG data
- preprocess.py handles signal conditioning, notably the bandpass filtering and normalization described in the README
This layer is the first internal boundary after raw dataset access and feeds both inference and training workflows.
4. Modeling and continual learning core
The core AI behavior is centered on a 1D convolutional neural network for ECG classification. The repository strongly suggests a staged lifecycle:
- base model training
- re-training / adaptation
- evaluation
The continuous-learning mechanism is backed by a Replay Buffer, which is explicitly stored as models/replay_buffer.npz.
5. Model artifacts and persistence
The models/ directory is the persistence boundary for learned state and results:
- ecg_cnn_base.pth and ADAPT-ECG-RETRAINED.pth are the main model weights
- ecg_cnn_base_meta.json stores model metadata
- retrain_history.json, fase3_resultados.json, and fase4_resultados.json capture training/evaluation outputs
This indicates the system is largely file-artifact driven rather than relying on a centralized database for ML state.
6. User-facing interface
The interactive front end is a Streamlit app in src/ui/app.py, with Streamlit configuration in .streamlit/config.toml. This UI is the presentation boundary for visualization and interactive inference, likely wrapping the preprocessing + model pipeline for users.
7. Configuration and environment control
src/config/settings.py centralizes application settings, while .env.example suggests environment-based configuration for paths or runtime parameters. This separation matters because the repo mixes notebooks, scripts, and UI, so configuration is the main way to keep the pipeline reproducible across entry points.
8. Experimentation and phase-based workflow
The notebooks/ folder shows the project’s research workflow:
- fase2_entrenamiento.ipynb
- fase3_reentrenamiento.ipynb
- fase4_evaluacion.ipynb
These notebooks map directly onto the project’s experimental phases and likely correspond to the artifacts in models/.
9. Automation and orchestration
The scripts/ directory contains the operational glue:
- run_phase1.py, train.ps1, retrain.ps1, run_api.ps1
- report/document generation scripts such as generar_informe_cnn.py, generar_informe_reentrenamiento.py, generar_marco_teorico.py, generar_notas_sesion.py
- conversion utilities like md_to_docx.py and md_to_pdf.py
These scripts form the batch/automation layer around the core ML pipeline and documentation workflow.
10. Database/schema boundary
There is a db/schema.sql, but the repository’s main architecture does not appear database-centric from the file layout. It likely defines a supporting schema or an auxiliary persistence layer, while the dominant runtime state remains in model files, JSON, and NPZ artifacts.
11. Documentation and deliverables
A large part of the repo is documentation-heavy: docs/ contains technical reports, architecture diagrams, and Markdown sources; Residencia_Profesional (1)/ contains thesis/report LaTeX assets, compiled PDFs, and institutional templates. This means the repo serves both as a functional ML system and as an academic deliverable generator.
12. How the main data flow fits together
The cleanest architectural diagram should show this sequence:
MIT-BIH ECG data → ingestion/preprocessing → CNN inference/training → retraining with replay buffer → saved weights/results → Streamlit UI and generated reports.
The key boundaries are the external dataset, the preprocessing layer, the model/retraining core, and the presentation/reporting layer.
Main entry points: fase3_reentrenamiento.ipynb Retrain · preprocess.py Preprocess · generar_informe_cnn.py Report scripts · ingest.py Ingest
Components 18
External data
Outside ECG source used as the canonical dataset boundary.
- MIT-BIH · PhysioNet arrhythmia data and annotations used as the source boundary.
Data pipeline
Ingestion and preprocessing for ECG signals.
- Ingest · Reads ECG records and organizes raw inputs for downstream processing.
src/data/ingest.py - Preprocess · Bandpass filtering, normalization, and other ECG conditioning steps.
src/data/preprocess.py - Settings · Central application settings for paths and runtime parameters.
src/config/settings.py
Model core
Training, retraining, replay, and evaluation around the CNN.
- Base train · Initial training stage for the 1D CNN classifier.
notebooks/fase2_entrenamiento.ipynb - ECG CNN · Primary classifier that predicts arrhythmia classes from ECG signals.
- Replay buffer · Stored replay samples used to reduce catastrophic forgetting during retraining.
models/replay_buffer.npz - Retrain · Adaptation loop that updates the model with replay-assisted retraining.
notebooks/fase3_reentrenamiento.ipynb - Evaluate · Assessment stage for retrained and base models.
notebooks/fase4_evaluacion.ipynb
Interface
Interactive UI and runtime entrypoints for users.
- Streamlit UI · Interactive interface for exploration, inference, and visualization.
src/ui/app.py
Automation
Scripts and notebooks that orchestrate experiments, retraining, and reporting.
- Phase 1 · Entry script for the first phase of the pipeline.
scripts/run_phase1.py - Auto retrain · Automation around retraining and periodic adaptation.
scripts/auto_retrain.py - Report scripts · Scripts that generate reports, notes, and document conversions.
scripts/generar_informe_cnn.py
Artifacts
Persisted models, histories, and report outputs.
- Base weights · Persisted initial CNN weights.
models/ecg_cnn_base.pth - Retained weights · Persisted retrained CNN weights.
models/ADAPT-ECG-RETRAINED.pth - Results JSON · Training and evaluation result files and history logs.
models/retrain_history.json
Docs
Technical and academic documentation deliverables.
- Tech docs · Technical documentation and architecture writeups.
docs/ADAPT-ECG_Documentacion_Tecnica.md - Thesis pack · Residencia Profesional thesis, templates, and compiled deliverables.
Residencia_Profesional (1)/Residencia_Main.tex
Connections 20
- MIT-BIH → Ingest: raw records
- Ingest → Preprocess: signals
- Settings → Ingest: paths/config
- Settings → Preprocess: params
- Preprocess → Base train: clean data
- Base train → ECG CNN: fit
- ECG CNN → Base weights: save
- Base weights → Retrain: start point
- Replay buffer → Retrain: memory
- Retrain → Retained weights: save
- Retrain → Results JSON: logs
- Retained weights → Evaluate: evaluate
- Preprocess → Streamlit UI: interactive input
- ECG CNN → Streamlit UI: predictions
- Phase 1 → Base train: orchestrate
- Auto retrain → Retrain: trigger
- Report scripts → Tech docs: generate
- Report scripts → Thesis pack: generate
- Results JSON → Report scripts: inputs
- Streamlit UI → Results JSON: surface outputs