# p-shekhar/adversarial-patch-transferability architecture

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

- Interactive diagram: https://gitdiagram.com/p-shekhar/adversarial-patch-transferability
- Repository: https://github.com/p-shekhar/adversarial-patch-transferability

## Overview

##### Main Components
a. Experiments Component:
- “Experiments” folder as the central experimental control unit.
- This includes multiple Jupyter Notebooks (e.g., Main.ipynb, Fig1.ipynb, Fig2, Fig3, Table notebooks) and generated figures (PDFs).
- These notebooks orchestrate the entire process: loading configurations, running training, generating plots, and evaluating results.

b. Configuration & Dataset Management:
- The “configs” directory holds the config.yaml, which contains crucial runtime parameters like dataset paths and file locations.
- The “dataset” folder contains modules for dataset handling (e.g., base_dataset.py and cityscapes.py) that read and preprocess images and masks.

c. Metrics & Loss Computation:
- The “metrics” folder defines custom performance measurement and loss calculations (e.g., loss.py and performance.py). They incorporate the adaptive adversarial loss function needed during training.

d. Patch Generation:
- The “patch” module includes the code (in create.py) for generating adversarial patches using the proposed variant of EOT.

e. Pretrained Models:
- The “pretrained_models” directory includes different segmentation models such as BisNetV1, BisNetV2, ICNet, and PIDNet, each with its own implementation files and supporting scripts. These models are the targets for adversarial attack experiments.
- Special attention should be given to the models’ sub-components (e.g., backbone, model definitions, etc.).

f. Trainer Module:
- The “trainer” folder contains training orchestration code (trainer.py) that manages the training loop, integrates patch generation, adaptive loss function, and updates model parameters.

g. Utility Functions:
- The “utils” folder offers helper modules (dirs.py, helper.py, utils.py) used across the project for file/directory management, logging, and miscellaneous functions.

##### Relationships and Interactions
- The configuration component feeds the dataset management system with paths and parameters required to load and preprocess the dataset.
- Once preprocessed data is available, the Trainer module leverages both the patch generator from the “patch” directory and the loss functions from “metrics” during the training phase.
- The Trainer orchestrates training with the pretrained models (loaded from “pretrained_models”), effectively testing the adversarial patch’s transferability.
- Experiments notebooks in the “Experiments” directory guide the execution flow, from initializing the training routines to plotting and visualizing performance metrics and figures.
- Utility functions support all modules by providing logging, error handling, and general-purpose services.

##### Architectural Patterns and Design Principles
- Modularity: Most functionalities are encapsulated in self-contained directories (data handling, training, evaluation, model definitions, etc.), thus promoting separation of concerns.
- Configurability: The use of a standalone config.yaml suggests that the system is built to support flexible experimentation—an essential feature for research work.
- Reusability & Extensibility: The clear separation of modules (e.g., metrics, patch, and pretrained models) allows for experiments with different adversarial strategies or models without major code modifications.
- Experiment-driven Flow: The project is designed as an experimental study, where components dynamically interact through training pipelines initiated by Jupyter Notebooks.

##### Relevant Technologies & Frameworks
- Although not explicitly mentioned in the file tree or README, it is likely that frameworks such as PyTorch are used for deep learning and model training.
- Jupyter Notebooks for experiment tracking and result visualization.
- YAML-based configuration management and possibly Python libraries for image and data processing.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Subgraph: Data Handling
    subgraph "Data Handling"
        CFG["Configs"]:::config
        DS["Dataset Loader"]:::dataset
    end

    %% Subgraph: Training Pipeline
    subgraph "Training Pipeline"
        TRN["Trainer Module"]:::trainer
        PG["Patch Generator"]:::patch
        MET["Metrics & Loss"]:::metrics
        PM["Pretrained Models"]:::model
    end

    %% Experiments & Visualization
    EXP["Experiments & Visualization"]:::experiment

    %% Utility Functions
    UTIL["Utility Functions"]:::utility

    %% Relationships
    CFG -->|"feeds"| DS
    DS -->|"inputTo"| TRN
    TRN -->|"integrates"| PG
    TRN -->|"uses"| MET
    TRN -->|"leverages"| PM
    EXP -->|"orchestrates"| TRN

    %% Utility support (dotted arrows)
    CFG -. "support" .-> UTIL
    DS -. "support" .-> UTIL
    TRN -. "support" .-> UTIL
    PG -. "support" .-> UTIL
    MET -. "support" .-> UTIL
    PM -. "support" .-> UTIL
    EXP -. "support" .-> UTIL

    %% Click Events
    click CFG "https://github.com/p-shekhar/adversarial-patch-transferability/blob/main/configs/config.yaml"
    click DS "https://github.com/p-shekhar/adversarial-patch-transferability/blob/main/dataset/base_dataset.py"
    click DS "https://github.com/p-shekhar/adversarial-patch-transferability/blob/main/dataset/cityscapes.py"
    click MET "https://github.com/p-shekhar/adversarial-patch-transferability/blob/main/metrics/loss.py"
    click MET "https://github.com/p-shekhar/adversarial-patch-transferability/blob/main/metrics/performance.py"
    click PG "https://github.com/p-shekhar/adversarial-patch-transferability/blob/main/patch/create.py"
    click PM "https://github.com/p-shekhar/adversarial-patch-transferability/blob/main/pretrained_models/BisNetV1/model.py"
    click PM "https://github.com/p-shekhar/adversarial-patch-transferability/blob/main/pretrained_models/ICNet/icnet.py"
    click TRN "https://github.com/p-shekhar/adversarial-patch-transferability/blob/main/trainer/trainer.py"
    click UTIL "https://github.com/p-shekhar/adversarial-patch-transferability/blob/main/utils/dirs.py"
    click UTIL "https://github.com/p-shekhar/adversarial-patch-transferability/blob/main/utils/helper.py"
    click UTIL "https://github.com/p-shekhar/adversarial-patch-transferability/blob/main/utils/utils.py"
    click EXP "https://github.com/p-shekhar/adversarial-patch-transferability/blob/main/Experiments/Main.ipynb"

    %% Styles
    classDef config fill:#ccf,stroke:#333,stroke-width:2px;
    classDef dataset fill:#fcf,stroke:#333,stroke-width:2px;
    classDef trainer fill:#cfc,stroke:#333,stroke-width:2px;
    classDef patch fill:#cff,stroke:#333,stroke-width:2px;
    classDef metrics fill:#ff9,stroke:#333,stroke-width:2px;
    classDef model fill:#9cf,stroke:#333,stroke-width:2px;
    classDef experiment fill:#f9c,stroke:#333,stroke-width:2px;
    classDef utility fill:#eee,stroke:#333,stroke-width:2px;
```
