# khoadoan106/backdoor_attacks architecture

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

- Interactive diagram: https://gitdiagram.com/khoadoan106/backdoor_attacks
- Repository: https://github.com/khoadoan106/backdoor_attacks

## Overview

##### Project Type & Purpose
- This is a specialized ML research project implementing adversarial backdoor attack methods.
- Its main purpose is to generate triggers and inject backdoors into classifier models (using techniques described in NeurIPS2022 and ICCV2021 papers).

##### Analyzing the File Structure
- Top-Level Directories and Files:
- The “python” directory contains the core code.
- “etc” holds environment and setup scripts (e.g., CUDA and environment setup, notebook runner).
- “requirements.txt” defines the Python dependencies.
- Inside “python”, there are several subdirectories:
- “attack_models” (e.g., autoencoders.py, unet.py): Contains models likely used for generating or processing triggers.
- “classifier_models” (various architecture definitions like densenet, resnet, etc.): This is where different neural network models for classification/regression are defined.
- “networks” and “utils”: Provide building blocks, custom network layers, utility functions for backdoor attack routines (e.g., dataloader management, backdoor utilities, etc.).
- Standalone scripts (e.g., lira_trigger_generation.py, lira_backdoor_injection.py, marksman_conditional_) that act as execution entry points for different stages of the attack (trigger generation vs. injection).

##### Main Components & Their Relationships
- Environment Setup & Configuration:
- Managed via “etc” scripts (setup_env, setup_cuda, install_torch_cuda_11.0, run_notebook) which prepare the runtime environment.
- Core ML Modules:
- Attack Models: Contains specific architectures (autoencoders, unet) used in formulating backdoor triggers.
- Classifier Models: A collection of pre-defined classifier architectures (VGG, ResNet, etc.) that are vulnerable to backdoor injection.
- Networks: General network components and blocks that might be shared across the above.
- Utils: Contains helper functions for model training, backdoor perturbation, data handling, and more.
- Experiment Pipelines:
- LIRA Pipeline: Split into two main scripts for trigger generation and backdoor injection. This pipeline first learns a trigger from the data, and then uses it to poison or fine-tune classifiers.
- Marksman Pipeline: Focuses on conditional backdoor injection using arbitrary target classes.
- Data and Execution Flow:
- Environment setup (through “etc”) ensures proper CUDA/Python configuration.
- The experimental scripts (in “python”) are executed to perform the following sequence:
1. Trigger Generation – where the attack model (from attack_models) interacts with a selected classifier (from classifier_models).
2. Backdoor Injection – where after trigger generation, the system triggers injection routines to poison classifier performance.
3. Data handling and utility functions (from utils) are used throughout these stages.

##### Architectural Patterns & Technologies
- Modularity: The code cleanly separates data handling, model definitions, and attack routines.
- Pipeline Pattern: Two-stage pipeline for LIRA (trigger generation and injection).
- Dependency Injection: Use of configuration scripts and arguments in the execution scripts to specify datasets, models, hyperparameters, etc.
- Technologies: Expect use of deep learning frameworks (e.g., PyTorch given the CUDA setup scripts), Python, and possibly external libraries (specified in requirements.txt).

## Diagram (Mermaid)

```mermaid
flowchart TD
    ES["Environment Setup & Config (etc)"]:::env

    subgraph "Experiment Pipelines"
        LIRA1["LIRA Trigger Generation"]:::script
        LIRA2["LIRA Backdoor Injection"]:::script
        LIRA1 --> LIRA2
        MARK1["Marksman Conditional Trigger Generation"]:::script
        MARK2["Marksman Conditional Backdoor Injection"]:::script
        MARK1 --> MARK2
    end

    subgraph "Core Modules"
        AM["Attack Models Module"]:::core
        CM["Classifier Models Module"]:::core
        SN["Shared Networks Module"]:::core
        UTIL["Utility Functions Module"]:::core
    end

    ES --> LIRA1
    ES --> MARK1

    LIRA1 --> AM
    LIRA1 --> CM
    LIRA1 --> UTIL
    LIRA1 --> SN

    LIRA2 --> AM
    LIRA2 --> CM
    LIRA2 --> UTIL
    LIRA2 --> SN

    MARK1 --> AM
    MARK1 --> CM
    MARK1 --> UTIL
    MARK1 --> SN

    MARK2 --> AM
    MARK2 --> CM
    MARK2 --> UTIL
    MARK2 --> SN

    click ES "https://github.com/khoadoan106/backdoor_attacks/tree/main/etc/"
    click AM "https://github.com/khoadoan106/backdoor_attacks/blob/main/python/attack_models/autoencoders.py"
    click AM "https://github.com/khoadoan106/backdoor_attacks/blob/main/python/attack_models/unet.py"
    click CM "https://github.com/khoadoan106/backdoor_attacks/tree/main/python/classifier_models/"
    click SN "https://github.com/khoadoan106/backdoor_attacks/tree/main/python/networks/"
    click UTIL "https://github.com/khoadoan106/backdoor_attacks/tree/main/python/utils/"
    click LIRA1 "https://github.com/khoadoan106/backdoor_attacks/blob/main/python/lira_trigger_generation.py"
    click LIRA2 "https://github.com/khoadoan106/backdoor_attacks/blob/main/python/lira_backdoor_injection.py"
    click MARK1 "https://github.com/khoadoan106/backdoor_attacks/blob/main/python/marksman_conditional_trigger_generation.py"
    click MARK2 "https://github.com/khoadoan106/backdoor_attacks/blob/main/python/marksman_conditional_backdoor_injection.py"

    classDef env fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef core fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef script fill:#FFD700,stroke:#000,stroke-width:2px;
```
