# mahenderreddyp/dental_xray_anamoly_detection architecture

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

- Interactive diagram: https://gitdiagram.com/mahenderreddyp/dental_xray_anamoly_detection
- Repository: https://github.com/mahenderreddyp/dental_xray_anamoly_detection

## Overview

##### Project Type and Purpose
- This is a research-oriented machine-learning pipeline (not a web app).
- Purpose: ingest panoramic X-rays, isolate the jaw, segment teeth, detect anomalies, and produce metrics & visualizations.

##### Main Components
A. Data Layer
- Raw Panoramic X-Ray Images (TUFTS-project folder)
- Expert & Student Annotation Stores (JSON, mask folders under TUFTS-project/Expert and TUFTS-project/Student)
- Generated Labels & Aggregated Data (labelGeneration.py, data_aggregation.py)

B. Preprocessing & Label Generation
- data_aggregation.py: merges image paths & label formats into YOLO-compatible datasets

C. Model Training & Experiment Tracking
- modelTraining.py
- medical_segmentation/exp_augmented{1…9}/args.yaml (hyperparameters)
- TensorBoard logs (events.out.tfevents.*)
- results.csv, best.pt & last.pt model weights
- YOLOv8 base weights (yolo11n.pt) and YOLOv8-seg template (yolov8n-seg.pt)

D. Inference Pipeline (Sequential Processing Steps)
1. Maxillomandibular Region Detection
– overlay_img.py + YOLO model → crops ROI
2. Tooth Segmentation
– YOLOv8-seg → outputs tooth masks
3. Anomaly Detection
– YOLOv8 detection & mask segmentation → identifies anomalies within tooth regions

E. Visualization & Evaluation
- OpenCV / Matplotlib scripts generate overlays (overlay_maxillomandibular.jpg, overlay_teeth.jpg, overlay_anomalies.jpg)
- Metrics computation: Precision/Recall/F1 curves, confusion matrices (images under exp_augmented9)
- README served as documentation

##### Relationships & Data Flows
- Raw Images & Annotations → Preprocessing Modules (data_aggregation.py, labelGeneration.py)
- Preprocessed Data → Training Module (modelTraining.py) → Experiment Folders (weights, logs, results)
- Trained Weights → Inference Pipeline (ROI Detection → Segmentation → Anomaly Detection)
- Inference Outputs → Visualization & Evaluation → Reports

##### Architectural Patterns & Design Principles
- Modular Pipeline: distinct modules for data prep, training, inference, and evaluation
- File-based “datastore” pattern: experiments isolated by folder, weights & logs co-located
- Sequential ML pipeline (not microservices) with clear stage separation

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Layer
    subgraph "Data Layer"
        direction TB
        RawImages["Raw Panoramic X-Ray Images"]:::data
        ExpertJSON["Expert Annotations (expert.json)"]:::data
        ExpertGaze["Expert Gaze Maps"]:::data
        StudentJSON["Student Annotations (student.json)"]:::data
        StudentMask["Student Masks"]:::data
    end

    %% Preprocessing & Label Generation
    subgraph "Preprocessing & Label Generation"
        direction TB
        DataAgg["data_aggregation.py"]:::preprocess
        LabelGen["labelGeneration.py"]:::preprocess
    end

    %% Model Training & Experiments
    subgraph "Model Training & Experiments"
        direction TB
        TrainScript["modelTraining.py"]:::model
        subgraph "Medical_Segmentation Experiments"
            direction TB
            Exp1["exp_augmented1 (args.yaml)"]:::model
            Exp2["exp_augmented2 (args.yaml)"]:::model
            Exp3["exp_augmented3 (args.yaml + logs)"]:::model
            Exp4["exp_augmented4 (args.yaml + logs)"]:::model
            Exp5["exp_augmented5 (full results)"]:::model
            Exp6["exp_augmented6 (full results)"]:::model
            Exp7["exp_augmented7 (args.yaml + logs)"]:::model
            Exp8["exp_augmented8 (full results)"]:::model
            Exp9["exp_augmented9 (full results)"]:::model
        end
        YOLOBase["YOLOv8 Base Weights (yolo11n.pt)"]:::model
        YOLOSeg["YOLOv8-Seg Template (yolov8n-seg.pt)"]:::model
    end

    %% Inference Pipeline
    subgraph "Inference Pipeline"
        direction TB
        ROIDetect["ROI Detection (overlay_img.py)"]:::model
        ToothSeg["Tooth Segmentation (YOLOv8-seg)"]:::model
        AnomalyDetect["Anomaly Detection (YOLOv8)"]:::model
        SegMask["Teeth Masks"]:::data
        SegBBox["Teeth BBoxes (JSON)"]:::data
    end

    %% Visualization & Evaluation
    subgraph "Visualization & Evaluation"
        direction TB
        Visualization["Overlay & Metrics Generation"]:::viz
        README["Project Documentation (README.md)"]:::viz
    end

    %% Data Flows
    RawImages -->|images & paths| DataAgg
    ExpertJSON -->|annotations| DataAgg
    ExpertGaze -->|gaze data| DataAgg
    StudentJSON -->|annotations| DataAgg
    StudentMask -->|mask data| DataAgg

    DataAgg -->|YOLO dataset| LabelGen
    LabelGen -->|YOLO labels| TrainScript

    TrainScript -->|trains models| Exp1 & Exp2 & Exp3 & Exp4 & Exp5 & Exp6 & Exp7 & Exp8 & Exp9
    YOLOBase -->|initial weights| TrainScript
    YOLOSeg -->|segmentation template| TrainScript

    Exp1 & Exp2 & Exp3 & Exp4 & Exp5 & Exp6 & Exp7 & Exp8 & Exp9 -->|best.pt & last.pt| ROIDetect

    ROIDetect -->|cropped ROI images| ToothSeg
    ToothSeg -->|tooth masks| SegMask
    ToothSeg -->|bboxes| SegBBox
    SegMask & SegBBox --> AnomalyDetect
    AnomalyDetect -->|anomaly overlays| Visualization
    AnomalyDetect -->|metrics data| Visualization

    Visualization --> README

    %% Click Events
    click RawImages "https://github.com/mahenderreddyp/dental_xray_anamoly_detection/tree/main/TUFTS-project/Segmentation/maxillomandibular"
    click ExpertJSON "https://github.com/mahenderreddyp/dental_xray_anamoly_detection/blob/main/TUFTS-project/Expert/expert.json"
    click ExpertGaze "https://github.com/mahenderreddyp/dental_xray_anamoly_detection/tree/main/TUFTS-project/Expert/gaze_map/"
    click StudentJSON "https://github.com/mahenderreddyp/dental_xray_anamoly_detection/blob/main/TUFTS-project/Student/student.json"
    click StudentMask "https://github.com/mahenderreddyp/dental_xray_anamoly_detection/tree/main/TUFTS-project/Student/mask/"
    click DataAgg "https://github.com/mahenderreddyp/dental_xray_anamoly_detection/blob/main/TUFTS-project/data_aggregation.py"
    click LabelGen "https://github.com/mahenderreddyp/dental_xray_anamoly_detection/blob/main/labelGeneration.py"
    click TrainScript "https://github.com/mahenderreddyp/dental_xray_anamoly_detection/blob/main/TUFTS-project/modelTraining.py"
    click Exp1 "https://github.com/mahenderreddyp/dental_xray_anamoly_detection/blob/main/TUFTS-project/medical_segmentation/exp_augmented/args.yaml"
    click Exp2 "https://github.com/mahenderreddyp/dental_xray_anamoly_detection/blob/main/TUFTS-project/medical_segmentation/exp_augmented2/args.yaml"
    click Exp3 "https://github.com/mahenderreddyp/dental_xray_anamoly_detection/tree/main/TUFTS-project/medical_segmentation/exp_augmented3/"
    click Exp4 "https://github.com/mahenderreddyp/dental_xray_anamoly_detection/tree/main/TUFTS-project/medical_segmentation/exp_augmented4/"
    click Exp5 "https://github.com/mahenderreddyp/dental_xray_anamoly_detection/tree/main/TUFTS-project/medical_segmentation/exp_augmented5/"
    click Exp6 "https://github.com/mahenderreddyp/dental_xray_anamoly_detection/tree/main/TUFTS-project/medical_segmentation/exp_augmented6/"
    click Exp7 "https://github.com/mahenderreddyp/dental_xray_anamoly_detection/tree/main/TUFTS-project/medical_segmentation/exp_augmented7/"
    click Exp8 "https://github.com/mahenderreddyp/dental_xray_anamoly_detection/tree/main/TUFTS-project/medical_segmentation/exp_augmented8/"
    click Exp9 "https://github.com/mahenderreddyp/dental_xray_anamoly_detection/tree/main/TUFTS-project/medical_segmentation/exp_augmented9/"
    click YOLOBase "https://github.com/mahenderreddyp/dental_xray_anamoly_detection/blob/main/TUFTS-project/yolo11n.pt"
    click YOLOSeg "https://github.com/mahenderreddyp/dental_xray_anamoly_detection/blob/main/TUFTS-project/yolov8n-seg.pt"
    click ROIDetect "https://github.com/mahenderreddyp/dental_xray_anamoly_detection/blob/main/TUFTS-project/overlay_img.py"
    click SegMask "https://github.com/mahenderreddyp/dental_xray_anamoly_detection/tree/main/TUFTS-project/Segmentation/teeth_mask/"
    click SegBBox "https://github.com/mahenderreddyp/dental_xray_anamoly_detection/blob/main/TUFTS-project/Segmentation/teeth_bbox.json"
    click README "https://github.com/mahenderreddyp/dental_xray_anamoly_detection/blob/main/README.md"

    %% Styles
    classDef data fill:#AED6F1,stroke:#3498DB,color:#1B4F72;
    classDef preprocess fill:#ABEBC6,stroke:#27AE60,color:#145A32;
    classDef model fill:#F9E79F,stroke:#F1C40F,color:#7D6608;
    classDef viz fill:#E8DAEF,stroke:#8E44AD,color:#512E5F;
```
