How junfu1115/danet works
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