# fardinabbasi/ml_fake_image_detection architecture

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

- Interactive diagram: https://gitdiagram.com/fardinabbasi/ml_fake_image_detection
- Repository: https://github.com/fardinabbasi/ml_fake_image_detection

## Overview

##### Main components
- Data Ingestion & Storage:
- Input images organized in two directories: “real” and “fake.”
- CSV files: “features.csv” and “labels.csv” representing the deep features.
- Feature Extraction Module:
- Handcrafted Feature Extraction: LBP and FFT methods implemented in code.
- Deep Features: Already provided but still integrated as a parallel track.
- Data Preprocessing:
- Cleaning (handling nulls, fixing or removing incorrect labels).
- Standardization (normalizing feature values).
- Train/Test Data Split.
- Dimension Reduction:
- PCA.
- LOL (Linear Optimal Low-Rank Projection).
- Classification Module:
- Logistic Regression (with Newton-Cholesky solver as mentioned).
- SVM (including grid search for hyperparameters).
- Random Forest (including hyperparameter tuning, e.g., number of estimators and max depth).
- Clustering Module:
- Mini-Batch K-Means (with evaluation using inertia/elbow method).
- Gaussian Mixture Models (with model selection via AIC/BIC).
- Result Evaluation & Reports:
- Visualization of classification evaluations (classification reports, confusion matrices).
- Clustering visualizations and sample decision tree from Random Forest.
- Supporting PDF reports and Jupyter Notebooks (Code.ipynb).

##### Relationships and data flow
- Both handcrafted and deep features are processed (handcrafted features are computed via the LBP and FFT methods, while deep features are read from provided CSV files).
- Next, funnel all features to the “Preprocessing” stage where data cleansing, standardization, and the train-test split occur.
- Then, the high-dimensional data is fed into the “Dimension Reduction” module where PCA and LOL transform the data into a more manageable size.
- Post dimension reduction, the refined feature set splits into two branches:
- One branch enters the “Classification” module (utilizing Logistic Regression, SVM, and Random Forest) to produce predictions.
- The other branch flows into the “Clustering” module (with Mini-Batch K-Means and GMM) for unsupervised analysis.
- Finally, evaluation results are generated and consolidated into visualization outputs (reports and images in the “readme_images” directory).

##### Important architectural patterns
- Pipeline/Modular architecture: Each processing step (extraction, preprocessing, reduction, classification, clustering) is a distinct module that feeds data into the next.
- Parallel feature processing: The design accommodates both handcrafted and deep features, highlighting design extensibility.
- Separation of concerns: Each component exactly targets a single functionality, making the system easier to understand and potentially scale.

##### Relevant technologies and libraries
- Image Processing: kimage I/O (skimage.io) and resize functions.
- Feature extraction: Custom implementation of LBP (using skimage.feature) and FFT from NumPy.
- Dimensionality reduction: Implementation of PCA and LOL.
- Machine Learning Models: scikit-learn (for Logistic Regression, SVM, Random Forest, and clustering algorithms).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Ingestion & Storage Layer
    subgraph "Data Ingestion & Storage"
        DI1("Image Directory: 'real'"):::storage
        DI2("Image Directory: 'fake'"):::storage
        DI3("CSV File: 'features.csv'"):::storage
        DI4("CSV File: 'labels.csv'"):::storage
    end

    %% Feature Extraction Module
    subgraph "Feature Extraction"
        FE("Handcrafted (LBP & FFT) & Deep Features"):::feature
    end

    %% Data Preprocessing Module
    subgraph "Data Preprocessing"
        DP("Data Cleaning, Normalization, Train/Test Split"):::preprocessing
    end

    %% Dimension Reduction Module
    subgraph "Dimension Reduction"
        DR("PCA & LOL"):::dimension
    end

    %% Classification Module
    subgraph "Classification Models"
        CL("Logistic Regression, SVM, Random Forest"):::classification
    end

    %% Clustering Module
    subgraph "Clustering Models"
        CLUS("Mini-Batch K-Means, Gaussian Mixture Models"):::clustering
    end

    %% Result Evaluation & Reports Module
    subgraph "Result Evaluation & Reports"
        EV("Consolidated Evaluation & Visualizations"):::evaluation
        REP1("readme_images"):::evaluation
        REP2("Report.pdf"):::evaluation
        REP3("FinalProject_Description.pdf"):::evaluation
        REP4("README.md"):::evaluation
    end

    %% Data Flow Connections
    DI1 --> FE
    DI2 --> FE
    DI3 --> FE
    DI4 --> FE

    FE --> DP
    DP --> DR

    DR --> CL
    DR --> CLUS

    CL --> EV
    CLUS --> EV
    EV --> REP1
    EV --> REP2
    EV --> REP3
    EV --> REP4

    %% Click Events for Data Ingestion & Storage
    click DI1 "https://github.com/fardinabbasi/ml_fake_image_detection/tree/main//real"
    click DI2 "https://github.com/fardinabbasi/ml_fake_image_detection/tree/main//fake"
    click DI3 "https://github.com/fardinabbasi/ml_fake_image_detection/blob/main//features.csv"
    click DI4 "https://github.com/fardinabbasi/ml_fake_image_detection/blob/main//labels.csv"

    %% Click Events for Code Notebook Modules (Feature Extraction, Preprocessing, Dimension Reduction, Classification, Clustering)
    click FE "https://github.com/fardinabbasi/ml_fake_image_detection/blob/main//Code.ipynb"
    click DP "https://github.com/fardinabbasi/ml_fake_image_detection/blob/main//Code.ipynb"
    click DR "https://github.com/fardinabbasi/ml_fake_image_detection/blob/main//Code.ipynb"
    click CL "https://github.com/fardinabbasi/ml_fake_image_detection/blob/main//Code.ipynb"
    click CLUS "https://github.com/fardinabbasi/ml_fake_image_detection/blob/main//Code.ipynb"

    %% Click Events for Result Evaluation & Reports
    click REP1 "https://github.com/fardinabbasi/ml_fake_image_detection/tree/main//readme_images"
    click REP2 "https://github.com/fardinabbasi/ml_fake_image_detection/blob/main//Report.pdf"
    click REP3 "https://github.com/fardinabbasi/ml_fake_image_detection/blob/main//FinalProject_Description.pdf"
    click REP4 "https://github.com/fardinabbasi/ml_fake_image_detection/blob/main//README.md"

    %% Styles
    classDef storage fill:#f9c,stroke:#333,stroke-width:2px;
    classDef feature fill:#bbf,stroke:#333,stroke-width:2px;
    classDef preprocessing fill:#dfd,stroke:#333,stroke-width:2px;
    classDef dimension fill:#fea,stroke:#333,stroke-width:2px;
    classDef classification fill:#aff,stroke:#333,stroke-width:2px;
    classDef clustering fill:#faf,stroke:#333,stroke-width:2px;
    classDef evaluation fill:#ffd,stroke:#333,stroke-width:2px;
```
