# twy-ui/sf-detr architecture

> Architecture diagram of the GitHub repository twy-ui/sf-detr, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/twy-ui/sf-detr
- Repository: https://github.com/twy-ui/sf-detr

## Overview

SF-DETR is a transformer-based detector for small objects in UAV imagery, built on an Ultralytics-style training and inference framework. Its documented workflow is to prepare labeled datasets, train a model, then validate or run inference and assess detection results. The model’s defining branches are spatial-frequency feature fusion and frequency-domain attention. The README documents those capabilities and entry points; source excerpts are limited, so internal runtime links beyond the indexed references are omitted where unverified.

Main entry points: [`ultralytics/engine/predictor.py`](https://github.com/twy-ui/sf-detr/blob/main/ultralytics/engine/predictor.py) (Prediction engine), [`ultralytics/engine/trainer.py`](https://github.com/twy-ui/sf-detr/blob/main/ultralytics/engine/trainer.py) (Training engine), [`ultralytics/nn/tasks.py`](https://github.com/twy-ui/sf-detr/blob/main/ultralytics/nn/tasks.py) (Detection models), [`val.py`](https://github.com/twy-ui/sf-detr/blob/main/val.py) (Validation entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["Detection workflow"]
  node_dataset[("UAV datasets")]
  node_preparation["Dataset preparation"]
  node_training_entry["Training entry<br/>[train.py]"]
  node_validation_entry["Validation entry<br/>[val.py]"]
  node_results["Detection results"]
end

subgraph group_model["SF-DETR model"]
  node_detector["Detection models<br/>[tasks.py]"]
  node_sf_fusion["SFH-MFF fusion"]
  node_frequency_attention["DL-AFIM attention"]
  node_backbones["Custom backbones"]
end

subgraph group_engine["Runtime engine"]
  node_trainer["Training engine<br/>[trainer.py]"]
  node_predictor["Prediction engine<br/>[predictor.py]"]
  node_backend["Model backends<br/>[autobackend.py]"]
  node_exporter["Model export<br/>[exporter.py]"]
end

subgraph group_data["Data and evaluation"]
  node_dataset_runtime["Data loading"]
  node_augment["Image augmentation<br/>[augment.py]"]
  node_validator["Validation engine<br/>[validator.py]"]
  node_metrics["Detection metrics<br/>[metrics.py]"]
  node_postprocess["Detection postprocess<br/>[ops.py]"]
end

subgraph group_support["Tracking and utilities"]
  node_tracker["Object tracking<br/>[track.py]"]
  node_visualization["Result visualization<br/>[plotting.py]"]
  node_model_config["Model configuration"]
end

node_user(("Researcher"))

node_user -->|"provides data"| node_dataset
node_dataset -->|"labels and converts"| node_preparation
node_user -->|"starts training"| node_training_entry
node_user -->|"starts validation"| node_validation_entry
node_training_entry -.->|"trains with"| node_trainer
node_validation_entry -.->|"validates with"| node_validator
node_detector -.->|"uses fusion"| node_sf_fusion
node_detector -.->|"uses attention"| node_frequency_attention
node_detector -->|"builds from"| node_backbones
node_trainer -.->|"trains model"| node_detector
node_trainer -->|"loads data"| node_dataset_runtime
node_dataset_runtime -->|"applies transforms"| node_augment
node_validator -.->|"computes metrics"| node_metrics
node_validation_entry -.->|"runs inference"| node_predictor
node_predictor -.->|"runs model"| node_backend
node_predictor -->|"filters detections"| node_postprocess
node_predictor -.->|"produces results"| node_results
node_validator -.->|"reports results"| node_results
node_predictor -.->|"renders outputs"| node_visualization
node_predictor -.->|"supports tracking"| node_tracker
node_trainer -.->|"uses settings"| node_model_config
node_user -.->|"exports model"| node_exporter

click node_preparation "https://github.com/twy-ui/sf-detr/tree/main/dataset"
click node_training_entry "https://github.com/twy-ui/sf-detr/blob/main/train.py"
click node_validation_entry "https://github.com/twy-ui/sf-detr/blob/main/val.py"
click node_detector "https://github.com/twy-ui/sf-detr/blob/main/ultralytics/nn/tasks.py"
click node_sf_fusion "https://github.com/twy-ui/sf-detr/tree/main/ultralytics/nn/extra_modules"
click node_frequency_attention "https://github.com/twy-ui/sf-detr/tree/main/ultralytics/nn/extra_modules"
click node_backbones "https://github.com/twy-ui/sf-detr/tree/main/ultralytics/nn/backbone"
click node_trainer "https://github.com/twy-ui/sf-detr/blob/main/ultralytics/engine/trainer.py"
click node_predictor "https://github.com/twy-ui/sf-detr/blob/main/ultralytics/engine/predictor.py"
click node_backend "https://github.com/twy-ui/sf-detr/blob/main/ultralytics/nn/autobackend.py"
click node_exporter "https://github.com/twy-ui/sf-detr/blob/main/ultralytics/engine/exporter.py"
click node_dataset_runtime "https://github.com/twy-ui/sf-detr/tree/main/ultralytics/data"
click node_augment "https://github.com/twy-ui/sf-detr/blob/main/ultralytics/data/augment.py"
click node_validator "https://github.com/twy-ui/sf-detr/blob/main/ultralytics/engine/validator.py"
click node_metrics "https://github.com/twy-ui/sf-detr/blob/main/ultralytics/utils/metrics.py"
click node_postprocess "https://github.com/twy-ui/sf-detr/blob/main/ultralytics/utils/ops.py"
click node_tracker "https://github.com/twy-ui/sf-detr/blob/main/ultralytics/trackers/track.py"
click node_visualization "https://github.com/twy-ui/sf-detr/blob/main/ultralytics/utils/plotting.py"
click node_model_config "https://github.com/twy-ui/sf-detr/tree/main/ultralytics/cfg"

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_dataset,node_preparation,node_training_entry,node_validation_entry,node_results toneBlue
class node_detector,node_sf_fusion,node_frequency_attention,node_backbones toneAmber
class node_trainer,node_predictor,node_backend,node_exporter toneMint
class node_dataset_runtime,node_augment,node_validator,node_metrics,node_postprocess toneRose
class node_tracker,node_visualization,node_model_config,node_user toneIndigo
```

## Components

### Detection workflow

- **UAV datasets**
- [Dataset preparation](https://github.com/twy-ui/sf-detr/tree/main/dataset): `dataset`
- [Training entry](https://github.com/twy-ui/sf-detr/blob/main/train.py): `train.py`
- [Validation entry](https://github.com/twy-ui/sf-detr/blob/main/val.py): `val.py`
- **Detection results**

### SF-DETR model

- [Detection models](https://github.com/twy-ui/sf-detr/blob/main/ultralytics/nn/tasks.py): `ultralytics/nn/tasks.py`
- [SFH-MFF fusion](https://github.com/twy-ui/sf-detr/tree/main/ultralytics/nn/extra_modules): `ultralytics/nn/extra_modules`
- [DL-AFIM attention](https://github.com/twy-ui/sf-detr/tree/main/ultralytics/nn/extra_modules): `ultralytics/nn/extra_modules`
- [Custom backbones](https://github.com/twy-ui/sf-detr/tree/main/ultralytics/nn/backbone): `ultralytics/nn/backbone`

### Runtime engine

- [Training engine](https://github.com/twy-ui/sf-detr/blob/main/ultralytics/engine/trainer.py): `ultralytics/engine/trainer.py`
- [Prediction engine](https://github.com/twy-ui/sf-detr/blob/main/ultralytics/engine/predictor.py): `ultralytics/engine/predictor.py`
- [Model backends](https://github.com/twy-ui/sf-detr/blob/main/ultralytics/nn/autobackend.py): `ultralytics/nn/autobackend.py`
- [Model export](https://github.com/twy-ui/sf-detr/blob/main/ultralytics/engine/exporter.py): `ultralytics/engine/exporter.py`

### Data and evaluation

- [Data loading](https://github.com/twy-ui/sf-detr/tree/main/ultralytics/data): `ultralytics/data`
- [Image augmentation](https://github.com/twy-ui/sf-detr/blob/main/ultralytics/data/augment.py): `ultralytics/data/augment.py`
- [Validation engine](https://github.com/twy-ui/sf-detr/blob/main/ultralytics/engine/validator.py): `ultralytics/engine/validator.py`
- [Detection metrics](https://github.com/twy-ui/sf-detr/blob/main/ultralytics/utils/metrics.py): `ultralytics/utils/metrics.py`
- [Detection postprocess](https://github.com/twy-ui/sf-detr/blob/main/ultralytics/utils/ops.py): `ultralytics/utils/ops.py`

### Tracking and utilities

- [Object tracking](https://github.com/twy-ui/sf-detr/blob/main/ultralytics/trackers/track.py): `ultralytics/trackers/track.py`
- [Result visualization](https://github.com/twy-ui/sf-detr/blob/main/ultralytics/utils/plotting.py): `ultralytics/utils/plotting.py`
- [Model configuration](https://github.com/twy-ui/sf-detr/tree/main/ultralytics/cfg): `ultralytics/cfg`

### Other components

- **Researcher**

## Connections

- Researcher → UAV datasets: provides data (evidence: `README.md`)
- UAV datasets → Dataset preparation: labels and converts (evidence: `README.md`)
- Researcher → Training entry: starts training (evidence: `README.md`)
- Researcher → Validation entry: starts validation (evidence: `README.md`)
- Training entry → Training engine: trains with
- Validation entry → Validation engine: validates with
- Detection models → SFH-MFF fusion: uses fusion (evidence: `README.md`)
- Detection models → DL-AFIM attention: uses attention (evidence: `README.md`)
- Detection models → Custom backbones: builds from (evidence: `ultralytics/nn/tasks.py`)
- Training engine → Detection models: trains model (evidence: `ultralytics/engine/trainer.py`)
- Training engine → Data loading: loads data (evidence: `ultralytics/engine/trainer.py`)
- Data loading → Image augmentation: applies transforms (evidence: `ultralytics/data/augment.py`)
- Validation engine → Detection metrics: computes metrics
- Validation entry → Prediction engine: runs inference
- Prediction engine → Model backends: runs model
- Prediction engine → Detection postprocess: filters detections (evidence: `ultralytics/utils/ops.py`)
- Prediction engine → Detection results: produces results
- Validation engine → Detection results: reports results
- Prediction engine → Result visualization: renders outputs
- Prediction engine → Object tracking: supports tracking
- Training engine → Model configuration: uses settings (evidence: `ultralytics/engine/trainer.py`)
- Researcher → Model export: exports model
