# shivammitra/parkinson-disease-detection architecture

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

- Interactive diagram: https://gitdiagram.com/shivammitra/parkinson-disease-detection
- Repository: https://github.com/shivammitra/parkinson-disease-detection

## Overview

#### Purpose and Entry Points
This is a local Parkinson’s-disease screening prototype that classifies spiral and wave drawing images as healthy or Parkinson’s, with optional clinical-data integration. Primary executable paths are training (`train.py`, `enhanced_train.py`), inference (`predict.py`, `enhanced_predict.py`), synthetic-data generation (`enhanced_data_generator.py`), and interactive diagnostics (`diagnostic_app.py`).

#### Configuration and Data Boundary
`config.py` centralizes model/data parameters and expected clinical columns. Image datasets are loaded and preprocessed through `data_loader.py`; the repository also includes a tabular source, `data.xlsx.csv`. Input data is an external filesystem boundary: images are expected in spiral/wave and class-specific directories, while trained artifacts are written to model-save locations configured by the application.

#### Data Preparation and Augmentation
The data pipeline converts drawing images into model-ready tensors and, for traditional ML, feature vectors. `enhanced_data_generator.py` creates configurable synthetic spiral and wave samples to expand training data; `prepare_data.py` and `generate_sample_data.py` support dataset preparation/sample generation. This stage separates raw images from normalized, augmented, or synthesized training inputs.

#### Model Families
Core model definitions are split between baseline and enhanced architectures:
- `model.py`: CNN, transfer-learning, and traditional-model-oriented implementations.
- `enhanced_model.py`: deeper CNN variants, MobileNet/EfficientNet adaptations, and ensemble behavior.
- `utils.py`: shared feature/processing support used across model workflows.

The system supports direct image CNN classification, pretrained transfer-learning backbones (VGG16/ResNet50/MobileNet/EfficientNet), HOG-driven Random Forest/SVM/Gradient Boosting models, and an ensemble that combines model predictions.

#### Training and Evaluation Flow
`train.py` dispatches baseline or classical model training, including selecting a named model or training all configured models. `enhanced_train.py` runs the enhanced model path with epochs, batch size, and augmentation controls. Training consumes prepared images/features, handles stated class-imbalance strategies such as SMOTE, and persists checkpoints for later inference. `evaluate.py` calculates classification quality including accuracy, precision/recall/F1, sensitivity, specificity, ROC/AUC.

#### Prediction and User Interfaces
CLI inference begins at `predict.py` or `enhanced_predict.py`: an image is preprocessed consistently with the selected saved model, then returned with class/confidence output. `predict.py --web_interface` exposes local interactive inference; `web_interface.py` and `debug_gradio.py` provide Gradio-facing UI paths. Additional front ends—`diagnostic_app.py`, `improved_app.py`, and `simple_app.py`—support uploading drawings, comparing model variants, visualizing confidence, and testing generated patterns.

#### Runtime and External Dependencies
The project is Python-based (`requirements.txt`, `setup.py`) and depends materially on TensorFlow for CNN/transfer-learning models, scikit-learn for HOG/classical ML and evaluation, OpenCV for image processing, and Gradio for local browser-based interfaces. There is no indicated hosted backend or external production service; execution, datasets, model checkpoints, and Gradio serving are local-machine concerns.

Main entry points: [`data_loader.py`](https://github.com/shivammitra/parkinson-disease-detection/blob/main/data_loader.py) (Image loader & preprocessing), [`train.py`](https://github.com/shivammitra/parkinson-disease-detection/blob/main/train.py) (Baseline/classical training), [`enhanced_train.py`](https://github.com/shivammitra/parkinson-disease-detection/blob/main/enhanced_train.py) (Enhanced training), [`predict.py`](https://github.com/shivammitra/parkinson-disease-detection/blob/main/predict.py) (Baseline inference)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data preparation"]
  node_external_images[("Drawing image filesystem<br/>external data")]
  node_clinical_data["Clinical tabular data<br/>CSV data<br/>[data.xlsx.csv]"]
  node_config["Configuration<br/>Python module<br/>[config.py]"]
  node_data_loader["Image loader &amp; preprocessing<br/>Python module<br/>[data_loader.py]"]
  node_synthetic_generator["Synthetic drawing generator<br/>Python script"]
  node_dataset_preparation["Dataset preparation<br/>Python scripts<br/>[prepare_data.py]"]
  node_prepared_data[("Prepared training inputs<br/>dataset")]
end

subgraph group_models["Model workflows"]
  node_baseline_models["Baseline model definitions<br/>Python module<br/>[model.py]"]
  node_enhanced_models["Enhanced model definitions<br/>Python module<br/>[enhanced_model.py]"]
  node_shared_utils["Shared features &amp; processing<br/>Python module<br/>[utils.py]"]
  node_baseline_training["Baseline/classical training<br/>Python entry point<br/>[train.py]"]
  node_enhanced_training["Enhanced training<br/>Python entry point<br/>[enhanced_train.py]"]
  node_evaluation["Evaluation metrics<br/>Python script<br/>[evaluate.py]"]
  node_model_artifacts[("Saved checkpoints<br/>local artifacts")]
end

subgraph group_interfaces["Local interfaces"]
  node_cli_inference["Baseline inference<br/>Python entry point<br/>[predict.py]"]
  node_enhanced_inference["Enhanced inference<br/>Python entry point"]
  node_gradio_ui["Gradio interfaces<br/>local UI<br/>[web_interface.py]"]
  node_diagnostic_app["Diagnostic app<br/>local UI<br/>[diagnostic_app.py]"]
  node_local_user(("Local user<br/>actor"))
end

node_config -->|"configures"| node_data_loader
node_external_images -->|"loads"| node_data_loader
node_synthetic_generator -->|"generates"| node_prepared_data
node_external_images -->|"prepares"| node_dataset_preparation
node_dataset_preparation -->|"produces"| node_prepared_data
node_data_loader -->|"normalizes"| node_prepared_data
node_shared_utils -->|"supports features"| node_baseline_models
node_prepared_data -->|"trains from"| node_baseline_training
node_prepared_data -->|"trains from"| node_enhanced_training
node_baseline_models -->|"selected by"| node_baseline_training
node_enhanced_models -->|"trained by"| node_enhanced_training
node_baseline_training -->|"saves"| node_model_artifacts
node_enhanced_training -->|"saves"| node_model_artifacts
node_model_artifacts -->|"evaluates"| node_evaluation
node_model_artifacts -->|"loads"| node_cli_inference
node_model_artifacts -->|"loads"| node_enhanced_inference
node_data_loader -->|"preprocesses input"| node_cli_inference
node_data_loader -->|"preprocesses input"| node_enhanced_inference
node_local_user -->|"uses"| node_gradio_ui
node_local_user -->|"uses"| node_diagnostic_app
node_gradio_ui -->|"invokes"| node_cli_inference
node_diagnostic_app -->|"invokes"| node_enhanced_inference

click node_clinical_data "https://github.com/shivammitra/parkinson-disease-detection/blob/main/data.xlsx.csv"
click node_config "https://github.com/shivammitra/parkinson-disease-detection/blob/main/config.py"
click node_data_loader "https://github.com/shivammitra/parkinson-disease-detection/blob/main/data_loader.py"
click node_synthetic_generator "https://github.com/shivammitra/parkinson-disease-detection/blob/main/enhanced_data_generator.py"
click node_dataset_preparation "https://github.com/shivammitra/parkinson-disease-detection/blob/main/prepare_data.py"
click node_baseline_models "https://github.com/shivammitra/parkinson-disease-detection/blob/main/model.py"
click node_enhanced_models "https://github.com/shivammitra/parkinson-disease-detection/blob/main/enhanced_model.py"
click node_shared_utils "https://github.com/shivammitra/parkinson-disease-detection/blob/main/utils.py"
click node_baseline_training "https://github.com/shivammitra/parkinson-disease-detection/blob/main/train.py"
click node_enhanced_training "https://github.com/shivammitra/parkinson-disease-detection/blob/main/enhanced_train.py"
click node_evaluation "https://github.com/shivammitra/parkinson-disease-detection/blob/main/evaluate.py"
click node_cli_inference "https://github.com/shivammitra/parkinson-disease-detection/blob/main/predict.py"
click node_enhanced_inference "https://github.com/shivammitra/parkinson-disease-detection/blob/main/enhanced_predict.py"
click node_gradio_ui "https://github.com/shivammitra/parkinson-disease-detection/blob/main/web_interface.py"
click node_diagnostic_app "https://github.com/shivammitra/parkinson-disease-detection/blob/main/diagnostic_app.py"

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_external_images,node_clinical_data,node_config,node_data_loader,node_synthetic_generator,node_dataset_preparation,node_prepared_data toneBlue
class node_baseline_models,node_enhanced_models,node_shared_utils,node_baseline_training,node_enhanced_training,node_evaluation,node_model_artifacts toneAmber
class node_cli_inference,node_enhanced_inference,node_gradio_ui,node_diagnostic_app,node_local_user toneMint
```

## Components

### Data preparation

- **Drawing image filesystem**: external data · Spiral and wave images organized by diagnostic class.
- [Clinical tabular data](https://github.com/shivammitra/parkinson-disease-detection/blob/main/data.xlsx.csv): CSV data · `data.xlsx.csv`
- [Configuration](https://github.com/shivammitra/parkinson-disease-detection/blob/main/config.py): Python module · Central model, data, and clinical-column settings. · `config.py`
- [Image loader & preprocessing](https://github.com/shivammitra/parkinson-disease-detection/blob/main/data_loader.py): Python module · Converts drawing images into normalized tensors and feature inputs. · `data_loader.py`
- [Synthetic drawing generator](https://github.com/shivammitra/parkinson-disease-detection/blob/main/enhanced_data_generator.py): Python script · Creates configurable spiral and wave training samples. · `enhanced_data_generator.py`
- [Dataset preparation](https://github.com/shivammitra/parkinson-disease-detection/blob/main/prepare_data.py): Python scripts · Prepares datasets and sample data. · `prepare_data.py`
- **Prepared training inputs**: dataset · Normalized, augmented, synthesized images and feature vectors.

### Model workflows

- [Baseline model definitions](https://github.com/shivammitra/parkinson-disease-detection/blob/main/model.py): Python module · CNN, transfer-learning, and classical-model implementations. · `model.py`
- [Enhanced model definitions](https://github.com/shivammitra/parkinson-disease-detection/blob/main/enhanced_model.py): Python module · Deep CNN, adapted backbones, and ensemble behavior. · `enhanced_model.py`
- [Shared features & processing](https://github.com/shivammitra/parkinson-disease-detection/blob/main/utils.py): Python module · Supports HOG-oriented classical and image model workflows. · `utils.py`
- [Baseline/classical training](https://github.com/shivammitra/parkinson-disease-detection/blob/main/train.py): Python entry point · Selects named or all baseline and traditional models. · `train.py`
- [Enhanced training](https://github.com/shivammitra/parkinson-disease-detection/blob/main/enhanced_train.py): Python entry point · Runs augmented enhanced-model training and imbalance handling. · `enhanced_train.py`
- [Evaluation metrics](https://github.com/shivammitra/parkinson-disease-detection/blob/main/evaluate.py): Python script · Calculates classification and ROC/AUC metrics. · `evaluate.py`
- **Saved checkpoints**: local artifacts · Locally persisted trained models for inference.

### Local interfaces

- [Baseline inference](https://github.com/shivammitra/parkinson-disease-detection/blob/main/predict.py): Python entry point · Preprocesses an image and returns class confidence. · `predict.py`
- [Enhanced inference](https://github.com/shivammitra/parkinson-disease-detection/blob/main/enhanced_predict.py): Python entry point · Runs inference using enhanced saved models. · `enhanced_predict.py`
- [Gradio interfaces](https://github.com/shivammitra/parkinson-disease-detection/blob/main/web_interface.py): local UI · Browser interfaces for upload, comparison, confidence, and diagnostics. · `web_interface.py`
- [Diagnostic app](https://github.com/shivammitra/parkinson-disease-detection/blob/main/diagnostic_app.py): local UI · Interactive drawing diagnostics and generated-pattern testing. · `diagnostic_app.py`
- **Local user**: actor

## Connections

- Configuration → Image loader & preprocessing: configures
- Drawing image filesystem → Image loader & preprocessing: loads
- Synthetic drawing generator → Prepared training inputs: generates
- Drawing image filesystem → Dataset preparation: prepares
- Dataset preparation → Prepared training inputs: produces
- Image loader & preprocessing → Prepared training inputs: normalizes
- Shared features & processing → Baseline model definitions: supports features
- Prepared training inputs → Baseline/classical training: trains from
- Prepared training inputs → Enhanced training: trains from
- Baseline model definitions → Baseline/classical training: selected by
- Enhanced model definitions → Enhanced training: trained by
- Baseline/classical training → Saved checkpoints: saves
- Enhanced training → Saved checkpoints: saves
- Saved checkpoints → Evaluation metrics: evaluates
- Saved checkpoints → Baseline inference: loads
- Saved checkpoints → Enhanced inference: loads
- Image loader & preprocessing → Baseline inference: preprocesses input
- Image loader & preprocessing → Enhanced inference: preprocesses input
- Local user → Gradio interfaces: uses
- Local user → Diagnostic app: uses
- Gradio interfaces → Baseline inference: invokes
- Diagnostic app → Enhanced inference: invokes
