# junfu1115/danet architecture

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

- Interactive diagram: https://gitdiagram.com/junfu1115/danet
- Repository: https://github.com/junfu1115/danet

## Overview

##### Project Type and Purpose
- This is a specialized deep‐learning research library for scene segmentation (Dual Attention Network).
- It provides a core “encoding” Python package (datasets, transforms, nn modules, model definitions), custom native operators (C++/CUDA extensions), CLI training/evaluation scripts, and documentation & CI pipelines.

##### File‐Structure Analysis
Top-level directories and their roles:
- encoding/…         → Core Python library
– datasets/         → Data loaders for Cityscapes, COCO, Pascal, etc.
– transforms/       → Image transforms & augmentations
– nn/               → Custom neural‐network layers (attention, encoding, syncbn)
– models/           → Backbone definitions & segmentation heads
– functions/        → Functional APIs including encoding ops
– lib/              → Native extensions (CPU/GPU) for performance-critical kernels
– utils/            → Helpers (metrics, schedulers, distributed training)
- experiments/…      → CLI scripts for recognition & segmentation training/evaluation
- scripts/…          → Dataset preparation scripts
- docs/…             → Sphinx‐based documentation
- .github/workflows  → CI/CD pipelines (unit tests, PyPI publishing, docs build)
- setup.py, setup.cfg → Packaging & installation

##### README Insights
- Research focus: Dual Attention mechanisms in PyTorch ≥1.4.
- Usage patterns:
- `python setup.py install` installs encoding lib & compiles native operators.
- CLI under experiments/ invokes the encoding library for training/testing.
- Dependencies: PyTorch, CUDA for GPU kernels, Sphinx for docs.

##### Main Components & Their Interactions
a. Components:
1. CLI Layer (experiments/*.py)
2. Core Library (encoding package)
3. Native Extensions (encoding/lib/cpu & /gpu)
4. Data Storage (on-disk datasets prepared via scripts/)
5. External Frameworks & Services:
– PyTorch, CUDA, NumPy
– GitHub Actions for CI
– PyPI for distribution
6. Documentation Pipeline (docs/ + Sphinx)

b. Relationships & Data Flow:
- User runs a CLI script → Loads config & arguments → Invokes classes in encoding/ (datasets → transforms → model → loss → optimizer)
- encoding/nn and encoding/functions call into native extensions for performance
- Data load pathways: scripts/prepare_* → datasets/ → PyTorch DataLoader
- Training loop writes checkpoints to experiments/segmentation/models/
- CI pipelines lint & test encoding/ & experiments/; build & publish package; build docs

c. Architectural Patterns & Principles:
- Modular Python package with clear separation: data, transforms, models, utils
- Plugin architecture for models & datasets via dynamic registry (model_store.py, get_transform.py)
- Native backend (C++/CUDA) for compute kernels
- CLI‐driven experiment orchestrator

d. Key Technologies & Frameworks:
- Python 3.6+
- PyTorch 1.4+
- CUDA/C++ for custom ops
- Sphinx for documentation
- GitHub Actions for CI/CD
- setuptools for packaging

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CLI Layer
    subgraph "CLI Layer"
        CLE["experiments/recognition"]:::cli
        CLS["experiments/segmentation"]:::cli
    end

    %% Core Library
    subgraph "Core Library"
        DS["encoding/datasets"]:::core
        TR["encoding/transforms"]:::core
        NN["encoding/nn"]:::core
        MD["encoding/models"]:::core
        FN["encoding/functions"]:::core
        UT["encoding/utils"]:::core
        PR["encoding/parallel.py"]:::core
    end

    %% Native Extensions
    subgraph "Native Extensions"
        CP["encoding/lib/cpu"]:::native
        GP["encoding/lib/gpu"]:::native
    end

    %% Data Preparation
    SCRIPT["scripts/"]:::data

    %% Documentation & CI/CD & Packaging
    DOCS["docs/"]:::external
    CI[".github/workflows/"]:::external
    PKG1["setup.py"]:::packaging
    PKG2["setup.cfg"]:::packaging
    DIST["dist/"]:::packaging

    %% External Frameworks & Services
    subgraph "External Frameworks"
        PT["PyTorch"]:::external
        CD["CUDA"]:::external
        NP["NumPy"]:::external
        SN["Sphinx"]:::external
        GA["GitHub Actions"]:::external
        PP["PyPI"]:::external
    end

    %% Relationships
    CLE -->|"uses"| DS
    CLE -->|"uses"| TR
    CLE -->|"uses"| MD
    CLE -->|"uses"| NN
    CLE -->|"uses"| FN
    CLS -->|"uses"| DS
    CLS -->|"uses"| TR
    CLS -->|"uses"| MD
    CLS -->|"uses"| NN
    CLS -->|"uses"| FN

    SCRIPT -->|"prepares data"| DS
    DS -->|"applies transforms"| TR

    NN -->|"calls native kernels"| CP
    NN -->|"calls native kernels"| GP
    FN -->|"calls native kernels"| CP
    FN -->|"calls native kernels"| GP

    PT --> DS
    PT --> TR
    PT --> NN
    PT --> MD
    CD --> CP
    CD --> GP
    NP --> DS

    SN --> DOCS
    GA --> CI

    CI -->|"tests"| DS
    CI -->|"tests"| CLE
    CI -->|"builds docs"| DOCS
    CI -->|"publishes package"| PP
    CI -->|"publishes dist"| DIST

    %% Click Events
    click CLE "https://github.com/junfu1115/danet/tree/master/experiments/"
    click CLS "https://github.com/junfu1115/danet/tree/master/experiments/segmentation/"
    click DS "https://github.com/junfu1115/danet/tree/master/encoding/datasets/"
    click TR "https://github.com/junfu1115/danet/tree/master/encoding/transforms/"
    click NN "https://github.com/junfu1115/danet/tree/master/encoding/nn/"
    click MD "https://github.com/junfu1115/danet/tree/master/encoding/models/"
    click FN "https://github.com/junfu1115/danet/tree/master/encoding/functions/"
    click UT "https://github.com/junfu1115/danet/tree/master/encoding/utils/"
    click PR "https://github.com/junfu1115/danet/blob/master/encoding/parallel.py"
    click CP "https://github.com/junfu1115/danet/tree/master/encoding/lib/cpu/"
    click GP "https://github.com/junfu1115/danet/tree/master/encoding/lib/gpu/"
    click SCRIPT "https://github.com/junfu1115/danet/tree/master/scripts/"
    click DOCS "https://github.com/junfu1115/danet/tree/master/docs/"
    click CI "https://github.com/junfu1115/danet/tree/master/.github/workflows/"
    click PKG1 "https://github.com/junfu1115/danet/blob/master/setup.py"
    click PKG2 "https://github.com/junfu1115/danet/blob/master/setup.cfg"
    click DIST "https://github.com/junfu1115/danet/tree/master/dist/"

    %% Styles
    classDef cli fill:#a8f0c6,stroke:#333,stroke-width:1px
    classDef core fill:#ade4f7,stroke:#333,stroke-width:1px
    classDef native fill:#f7d29d,stroke:#333,stroke-width:1px
    classDef data fill:#d9b38c,stroke:#333,stroke-width:1px
    classDef external fill:#cccccc,stroke:#333,stroke-width:1px
    classDef packaging fill:#e0e0e0,stroke:#333,stroke-width:1px
```
