# yjyddq/dlif architecture

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

- Interactive diagram: https://gitdiagram.com/yjyddq/dlif
- Repository: https://github.com/yjyddq/dlif

## Overview

##### Project type and purpose
- This is a research‐oriented machine‐learning codebase implementing “DLIF,” a generalized face anti‐spoofing method. It provides data preprocessing, dataset loading, model definition, loss functions, training and testing protocols, and evaluation utilities.

##### File structure
- Top‐level directories:
- data_prepare: scripts to convert raw videos to aligned, cropped images
- dataset: Dataset and DataLoader wrappers
- loss: definition of main and triplet losses
- models: core network module(s)
- protocol: multiple folds/domains, each with config.py, train.py, test.py
- utils: evaluation, statistics, and helper functions
- Patterns: a clear ML pipeline (preprocess → load → train/infer → evaluate) with modular separation of components.
- Config files per protocol drive hyperparameters and dataset splits.
- The project uses PyTorch with distributed launches (torch.distributed).

##### README insights
- It details required external libs (MTCNN face detector, PyTorch, CUDA) and target datasets.

##### Detail without over-chunking
- Every major module listed above.
- Don’t split beyond functional layers (e.g., no need to show every single loss file separately—group them).
- Config→train/test coupling is clear for each protocol.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Dependencies
    subgraph "External Dependencies"
        MTCNN["MTCNN Face Detector"]:::external
        PyTorch["PyTorch & CUDA"]:::external
        GPU["GPU Cluster"]:::external
    end

    %% Data Layer
    subgraph "Data Layer"
        RV[/ "Raw Video Storage" /]:::data
        VID["Video2Img Script"]:::data
        CR["CropResize Script"]:::data
        DSImage["Aligned & Cropped Images"]:::data
    end

    %% Data Loading
    subgraph "Data Loading"
        DSET["Dataset Module"]:::data
        DLOAD["DataLoader"]:::data
    end

    %% Model & Loss
    subgraph "Model & Loss"
        Model(("Model Module")):::comp
        Losses(("Main Loss")):::comp
        Triplet(("Triplet Loss")):::comp
    end

    %% Protocols
    subgraph "Protocols"
        Config["config.py"]:::orch
        Train["train.py"]:::orch
        Test["test.py"]:::orch
    end

    %% Utilities
    subgraph "Utilities"
        Eval{"Evaluation"}:::util
        Stat{"Statistics"}:::util
        Utils["Helpers"]:::util
    end

    %% Artifacts
    subgraph "Artifacts"
        CP["Checkpoints"]:::art
        Logs["Logs"]:::art
        Metrics["Metrics"]:::art
    end

    %% Data Flow
    MTCNN -->|detect faces| VID
    RV -->|"raw videos"| VID
    VID -->|"aligned frames"| CR
    CR -->|"preprocessed images"| DSImage
    DSImage -->|"images"| DSET
    DSET -->|"dataset object"| DLOAD
    DLOAD -->|"batches"| Model

    PyTorch --> Model
    GPU --> Train
    GPU --> Test

    Model -->|"features"| Losses
    Model -->|"features"| Triplet
    Losses -->|"loss"| Train
    Triplet -->|"hard_triplet loss"| Train
    Train -->|"gradients"| Model
    Train -->|"save"| CP
    Train -->|"write"| Logs

    Config --> Train
    Config --> Test

    Test -->|"load checkpoint"| CP
    Test -->|"infer"| Model
    Test -->|"results"| Eval
    Eval -->|"metrics"| Stat
    Stat -->|"report"| Metrics
    Utils --> Eval
    Utils --> Stat

    %% Click Events
    click VID "https://github.com/yjyddq/dlif/blob/main/data_prepare/video2img.py"
    click CR "https://github.com/yjyddq/dlif/blob/main/data_prepare/crop_resize.py"
    click DSET "https://github.com/yjyddq/dlif/blob/main/dataset/dataset.py"
    click DLOAD "https://github.com/yjyddq/dlif/blob/main/dataset/get_loader.py"
    click Model "https://github.com/yjyddq/dlif/blob/main/models/module.py"
    click Losses "https://github.com/yjyddq/dlif/blob/main/loss/losses.py"
    click Triplet "https://github.com/yjyddq/dlif/blob/main/loss/hard_triplet_loss.py"
    click Train "https://github.com/yjyddq/dlif/blob/main/protocol/I_C_M_to_O/train.py"
    click Test "https://github.com/yjyddq/dlif/blob/main/protocol/I_C_M_to_O/test.py"
    click Config "https://github.com/yjyddq/dlif/blob/main/protocol/I_C_M_to_O/config.py"
    click Eval "https://github.com/yjyddq/dlif/blob/main/utils/evaluate.py"
    click Stat "https://github.com/yjyddq/dlif/blob/main/utils/statistic.py"
    click Utils "https://github.com/yjyddq/dlif/blob/main/utils/utils.py"
    click MTCNN "https://github.com/yjyddq/dlif/blob/main/assets/Motivation.pdf"
    click PyTorch "https://github.com/yjyddq/dlif/blob/main/assets/architecture.pdf"
    click RV "https://github.com/yjyddq/dlif/blob/main/README.md"
    click Logs "https://github.com/yjyddq/dlif/tree/main/LICENSE"

    %% Styles
    classDef data fill:#a2d2ff,stroke:#0d3b66;
    classDef comp fill:#c8e6c9,stroke:#2e7d32;
    classDef orch fill:#ffe0b2,stroke:#ef6c00;
    classDef util fill:#e1bee7,stroke:#6a1b9a;
    classDef art fill:#e0e0e0,stroke:#616161;
    classDef external stroke-dasharray:5 5,fill:#ffffff,stroke:#000000;
```
