# xavysp/dexined architecture

> Architecture diagram of the GitHub repository xavysp/dexined, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/xavysp/dexined
- Repository: https://github.com/xavysp/dexined

## Overview

#### Purpose and primary entry points
DexiNed is a CNN-based perceptual edge-detection project. The current implementation is PyTorch and supports both training and checkpoint-based inference through `main.py`. Inputs are images or dataset image/edge-label pairs; outputs are multi-scale/fused edge maps and saved evaluation artifacts.  
Paths: `main.py`, `model.py`, `data/lena_std.tif`

#### Execution orchestration
`main.py` is the operational boundary: argument parsing selects test data and testing vs. training mode, obtains dataset metadata, builds data loaders/model/loss, and drives training or inference. Testing expects externally downloaded checkpoints in a prescribed `checkpoints/...` location.  
Paths: `main.py`, `datasets.py`, `losses.py`

#### Dataset configuration and ingestion
Dataset identities and filesystem conventions are centralized in `datasets.py`, including BIPED as the training default and named benchmark/test sets. The loader layer converts images and edge annotations into model-ready tensors; the repository includes a CLASSIC-style sample-image path and an MDBD list example. Image dimensions must be multiples of 16 because of model downsampling.  
Paths: `datasets.py`, `dataset-lists/MDBD/test_pair.lst`, `data/lena_std.tif`

#### DexiNed neural architecture
The PyTorch model is defined by the DexiNed class in `model.py`. It is a dense extreme-inception encoder/decoder-style edge detector that produces multiple side outputs plus a fused result, enabling deep supervision in a single training stage and inference-time edge prediction.  
Paths: `model.py`, `main.py`

#### Training objective and optimization boundary
`losses.py` contains the BDCN-derived edge loss used to supervise the model’s multiple outputs against boundary labels. Training is from scratch rather than dependent on pretrained weights. The training loop and checkpoint lifecycle are controlled by `main.py`; checkpoint files are external runtime assets rather than repository contents.  
Paths: `losses.py`, `main.py`

#### Image processing and result handling
Shared image-oriented operations are separated from the model and training orchestration in the utility package. These support preparation and/or serialization of visual edge-detection results. Existing `res/` content is benchmark output, organized by dataset and DexiNed variant (`-a`, `-f`), not application runtime infrastructure.  
Paths: `utils/image.py`, `res/BIPED/DexiNed-a/eval_bdry.txt`, `res/MDBD/DexiNed-f/ios_res.txt`

#### Runtime variants and dependencies
The primary runtime is Python 3.7+ with PyTorch, OpenCV, Matplotlib, Kornia, NumPy, h5py, and PIL. TensorFlow implementations are distinct branches: `legacy/` is the historical TF1 implementation, while `DexiNed-TF2/` is an incomplete/preliminary TF2 track. Training data and pretrained checkpoints are obtained from external dataset hosts and Google Drive; no service backend is present.  
Paths: `legacy/train.py`, `legacy/models/dexined.py`, `DexiNed-TF2/mainTF.py`

Main entry points: [`datasets.py`](https://github.com/xavysp/dexined/blob/master/datasets.py) (Tensor loaders), [`main.py`](https://github.com/xavysp/dexined/blob/master/main.py) (main.py), [`model.py`](https://github.com/xavysp/dexined/blob/master/model.py) (Side outputs + fusion), [`utils/image.py`](https://github.com/xavysp/dexined/blob/master/utils/image.py) (Image utilities)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_pytorch["PyTorch pipeline"]
  node_main{{"main.py<br/>CLI orchestrator<br/>[main.py]"}}
  node_datasets["Dataset registry<br/>dataset configuration<br/>[datasets.py]"]
  node_loader["Tensor loaders<br/>data ingestion<br/>[datasets.py]"]
  node_model["DexiNed<br/>PyTorch edge model<br/>[model.py]"]
  node_side_outputs["Side outputs + fusion<br/>model output stage<br/>[model.py]"]
  node_loss["BDCN edge loss<br/>training objective<br/>[losses.py]"]
  node_image_utils["Image utilities<br/>image processing<br/>[image.py]"]
end

subgraph group_data["Data and artifacts"]
  node_checkpoints[("External checkpoints<br/>runtime asset")]
  node_biped_data[("BIPED training data<br/>external dataset")]
  node_mdbd_list["MDBD test pairs<br/>dataset manifest<br/>[test_pair.lst]"]
  node_sample_image["CLASSIC sample image<br/>image input<br/>[lena_std.tif]"]
  node_results["Benchmark results<br/>evaluation artifacts<br/>[eval_bdry.txt]"]
  node_mdbd_results["MDBD evaluation results<br/>evaluation artifact<br/>[ios_res.txt]"]
end

subgraph group_alternate["Alternative runtimes"]
  node_legacy_tf1["Legacy TF1 training<br/>historical runtime<br/>[train.py]"]
  node_legacy_tf1_model["Legacy TF1 DexiNed<br/>TensorFlow model<br/>[dexined.py]"]
  node_tf2["Preliminary TF2 track<br/>incomplete runtime<br/>[mainTF.py]"]
end

node_main -->|"selects dataset"| node_datasets
node_datasets -->|"configures"| node_loader
node_biped_data -->|"image/label pairs"| node_loader
node_mdbd_list -->|"test pairs"| node_loader
node_sample_image -->|"sample input"| node_loader
node_main -->|"builds"| node_loader
node_main -->|"builds"| node_model
node_loader -->|"tensors"| node_model
node_model -->|"predicts"| node_side_outputs
node_main -->|"uses for training"| node_loss
node_side_outputs -->|"deep supervision"| node_loss
node_main -.->|"loads/saves"| node_checkpoints
node_side_outputs -->|"edge maps"| node_image_utils
node_image_utils -->|"writes evaluation"| node_results
node_image_utils -->|"writes evaluation"| node_mdbd_results
node_legacy_tf1 -->|"uses"| node_legacy_tf1_model

click node_main "https://github.com/xavysp/dexined/blob/master/main.py"
click node_datasets "https://github.com/xavysp/dexined/blob/master/datasets.py"
click node_loader "https://github.com/xavysp/dexined/blob/master/datasets.py"
click node_model "https://github.com/xavysp/dexined/blob/master/model.py"
click node_side_outputs "https://github.com/xavysp/dexined/blob/master/model.py"
click node_loss "https://github.com/xavysp/dexined/blob/master/losses.py"
click node_image_utils "https://github.com/xavysp/dexined/blob/master/utils/image.py"
click node_mdbd_list "https://github.com/xavysp/dexined/blob/master/dataset-lists/MDBD/test_pair.lst"
click node_sample_image "https://github.com/xavysp/dexined/blob/master/data/lena_std.tif"
click node_results "https://github.com/xavysp/dexined/blob/master/res/BIPED/DexiNed-a/eval_bdry.txt"
click node_mdbd_results "https://github.com/xavysp/dexined/blob/master/res/MDBD/DexiNed-f/ios_res.txt"
click node_legacy_tf1 "https://github.com/xavysp/dexined/blob/master/legacy/train.py"
click node_legacy_tf1_model "https://github.com/xavysp/dexined/blob/master/legacy/models/dexined.py"
click node_tf2 "https://github.com/xavysp/dexined/blob/master/DexiNed-TF2/mainTF.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_datasets,node_loader,node_model,node_side_outputs,node_loss,node_image_utils toneBlue
class node_checkpoints,node_biped_data,node_mdbd_list,node_sample_image,node_results,node_mdbd_results toneAmber
class node_legacy_tf1,node_legacy_tf1_model,node_tf2 toneMint
```

## Components

### PyTorch pipeline

Current training and inference implementation.

- [main.py](https://github.com/xavysp/dexined/blob/master/main.py): CLI orchestrator · Selects training or inference and controls checkpoint lifecycle. · `main.py`
- [Dataset registry](https://github.com/xavysp/dexined/blob/master/datasets.py): dataset configuration · Defines dataset identities and filesystem conventions. · `datasets.py`
- [Tensor loaders](https://github.com/xavysp/dexined/blob/master/datasets.py): data ingestion · Converts images and boundary labels into model-ready tensors. · `datasets.py`
- [DexiNed](https://github.com/xavysp/dexined/blob/master/model.py): PyTorch edge model · Dense encoder/decoder edge detector. · `model.py`
- [Side outputs + fusion](https://github.com/xavysp/dexined/blob/master/model.py): model output stage · Produces multi-scale edge maps and a fused prediction. · `model.py`
- [BDCN edge loss](https://github.com/xavysp/dexined/blob/master/losses.py): training objective · Supervises each model output against boundary labels. · `losses.py`
- [Image utilities](https://github.com/xavysp/dexined/blob/master/utils/image.py): image processing · Prepares and serializes visual edge results. · `utils/image.py`

### Data and artifacts

Repository inputs, lists, and benchmark outputs.

- **External checkpoints**: runtime asset · Downloaded weights required for checkpoint-based inference.
- **BIPED training data**: external dataset · Default training dataset obtained externally.
- [MDBD test pairs](https://github.com/xavysp/dexined/blob/master/dataset-lists/MDBD/test_pair.lst): dataset manifest · `dataset-lists/MDBD/test_pair.lst`
- [CLASSIC sample image](https://github.com/xavysp/dexined/blob/master/data/lena_std.tif): image input · `data/lena_std.tif`
- [Benchmark results](https://github.com/xavysp/dexined/blob/master/res/BIPED/DexiNed-a/eval_bdry.txt): evaluation artifacts · Stored per dataset and DexiNed variant. · `res/BIPED/DexiNed-a/eval_bdry.txt`
- [MDBD evaluation results](https://github.com/xavysp/dexined/blob/master/res/MDBD/DexiNed-f/ios_res.txt): evaluation artifact · `res/MDBD/DexiNed-f/ios_res.txt`

### Alternative runtimes

Separate TensorFlow implementation tracks.

- [Legacy TF1 training](https://github.com/xavysp/dexined/blob/master/legacy/train.py): historical runtime · Separate historical TensorFlow 1 implementation. · `legacy/train.py`
- [Legacy TF1 DexiNed](https://github.com/xavysp/dexined/blob/master/legacy/models/dexined.py): TensorFlow model · `legacy/models/dexined.py`
- [Preliminary TF2 track](https://github.com/xavysp/dexined/blob/master/DexiNed-TF2/mainTF.py): incomplete runtime · Separate incomplete TensorFlow 2 implementation. · `DexiNed-TF2/mainTF.py`

## Connections

- main.py → Dataset registry: selects dataset
- Dataset registry → Tensor loaders: configures
- BIPED training data → Tensor loaders: image/label pairs
- MDBD test pairs → Tensor loaders: test pairs
- CLASSIC sample image → Tensor loaders: sample input
- main.py → Tensor loaders: builds
- main.py → DexiNed: builds
- Tensor loaders → DexiNed: tensors
- DexiNed → Side outputs + fusion: predicts
- main.py → BDCN edge loss: uses for training
- Side outputs + fusion → BDCN edge loss: deep supervision
- main.py → External checkpoints: loads/saves
- Side outputs + fusion → Image utilities: edge maps
- Image utilities → Benchmark results: writes evaluation
- Image utilities → MDBD evaluation results: writes evaluation
- Legacy TF1 training → Legacy TF1 DexiNed: uses
