# exmorgan-alter/afafsgd architecture

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

- Interactive diagram: https://gitdiagram.com/exmorgan-alter/afafsgd
- Repository: https://github.com/exmorgan-alter/afafsgd

## Overview

1. **Project purpose**
   - This repository implements the method from the paper *“Anchor-Aware Similarity Cohesion in Target Frames Enables Predicting Temporal Moment Boundaries in 2D”*.
   - Architecturally, it is a **PyTorch temporal moment boundary localization system**: it takes prepared video/query data, predicts temporal boundaries, and evaluates them on the QHV benchmark.

2. **Top-level execution flow**
   - `main.py` is the main entry point for training and/or validation.
   - `warm_up.py` suggests a separate startup phase for learning-rate warmup or early training scheduling.
   - The typical flow is: dataset loading → model forward pass → loss computation → optimizer update → checkpointing/evaluation.

3. **Dataset boundary**
   - `dataset/` contains the data access layer, with `QHVdata.py` likely implementing the dataset-specific loader and `base.py` providing shared dataset behavior.
   - The README says to prepare data according to **Moment-DETR**, so the repository likely consumes **preprocessed features and annotations** rather than raw video decoding.
   - This is an important architectural boundary: data preparation happens outside the repo, while this repo focuses on training and inference over the prepared tensors/metadata.

4. **Model composition**
   - `model/` is split into reusable components and task-specific detectors.
   - `model/model.py`, `model/base.py`, and `model/detect.py` appear to define the overall model wrapper and inference-facing interfaces.
   - This separation suggests the project is modular: backbone/feature encoding is decoupled from the boundary-prediction head.

5. **Backbone / feature encoders**
   - `model/CNNs/` contains CNN options such as `resnet.py`, `mknet.py`, and `vanilla.py`.
   - These are likely interchangeable visual encoders or feature transformation blocks.
   - From an architecture-diagram perspective, this is the **feature extraction stage** before temporal reasoning.

6. **Temporal and detection modules**
   - `model/temporal.py` handles temporal aggregation or sequence modeling across frames/clips.
   - `model/Det/` contains the detection stack:
     - `Conv.py` for convolutional processing,
     - `attention.py` for attention-based interaction,
     - `detr.py` for DETR-style temporal set prediction,
     - `tan.py` for temporal anchor-based localization.
   - This directory is the core of the paper’s method: it likely converts encoded video/query features into boundary predictions on a temporal grid or set of candidate moments.

7. **Algorithmic focus**
   - The paper title indicates **anchor-aware similarity cohesion** and **2D target-frame boundary prediction**.
   - In architectural terms, the system likely builds a 2D temporal representation of candidate segments or frame pairs, then scores boundary coherence using anchor-aware mechanisms.
   - That means the main computation is not just classification, but structured temporal localization with boundary-sensitive prediction.

8. **Loss and supervision**
   - `loss.py` centralizes training objectives.
   - Given the task, this likely combines localization losses for start/end boundaries with auxiliary matching or classification terms from the detector head.
   - Keeping losses separate from model code makes it easier to swap detector variants while preserving the same training objective.

9. **Evaluation path**
   - `eval/eval_qhv.py` handles benchmark-specific evaluation for QHV.
   - This is likely where predicted moments are converted into metrics such as IoU-based accuracy, recall, or mAP-style scores depending on the benchmark protocol.
   - Evaluation is isolated from training, which helps keep the inference contract stable.

10. **Utilities and shared helpers**
   - `utilize.py` likely contains miscellaneous helpers such as tensor/device utilities, logging, metrics, or checkpoint support.
   - `model/__init__.py`, `dataset/__init__.py`, and `eval/__init__.py` indicate package-level exports for cleaner imports.
   - Overall, the repo is organized around a clean pipeline: **prepared dataset → modular encoder/detector model → localization losses → QHV evaluation**.

Main entry points: [`model/detect.py`](https://github.com/exmorgan-alter/afafsgd/blob/main/model/detect.py) (detect.py), [`model/model.py`](https://github.com/exmorgan-alter/afafsgd/blob/main/model/model.py) (model.py), [`main.py`](https://github.com/exmorgan-alter/afafsgd/blob/main/main.py) (main.py), [`loss.py`](https://github.com/exmorgan-alter/afafsgd/blob/main/loss.py) (loss.py)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_training["Training"]
  node_main_py["main.py<br/>entrypoint<br/>[main.py]"]
  node_warm_up_py["warm_up.py<br/>schedule<br/>[warm_up.py]"]
  node_loss_py["loss.py<br/>losses<br/>[loss.py]"]
  node_utilize_py["utilize.py<br/>helpers<br/>[utilize.py]"]
end

subgraph group_data["Data"]
  node_qhvdata_py[("QHVdata.py<br/>dataset loader<br/>[QHVdata.py]")]
  node_dataset_base_py["base.py<br/>dataset base<br/>[base.py]"]
end

subgraph group_model["Model"]
  node_model_py["model.py<br/>model wrapper<br/>[model.py]"]
  node_model_base_py["base.py<br/>model base<br/>[base.py]"]
  node_detect_py["detect.py<br/>inference<br/>[detect.py]"]
  node_temporal_py["temporal.py<br/>temporal module<br/>[temporal.py]"]
  node_cnn_resnet_py["resnet.py<br/>cnn encoder<br/>[resnet.py]"]
  node_cnn_mknet_py["mknet.py<br/>cnn encoder<br/>[mknet.py]"]
  node_cnn_vanilla_py["vanilla.py<br/>cnn encoder<br/>[vanilla.py]"]
  node_det_conv_py["Conv.py<br/>detector block<br/>[Conv.py]"]
  node_det_attention_py["attention.py<br/>detector block<br/>[attention.py]"]
  node_det_detr_py["detr.py<br/>detector head<br/>[detr.py]"]
  node_det_tan_py["tan.py<br/>detector head<br/>[tan.py]"]
end

subgraph group_evaluation["Evaluation"]
  node_eval_qhv_py["eval_qhv.py<br/>evaluation<br/>[eval_qhv.py]"]
end

node_main_py -->|"loads"| node_qhvdata_py
node_main_py -->|"runs"| node_model_py
node_main_py -->|"optimizes"| node_loss_py
node_main_py -->|"validates"| node_eval_qhv_py
node_main_py -->|"schedules"| node_warm_up_py
node_main_py -->|"uses"| node_utilize_py
node_qhvdata_py -->|"extends"| node_dataset_base_py
node_model_py -->|"composes"| node_model_base_py
node_model_py -->|"exposes"| node_detect_py
node_model_py -->|"includes"| node_temporal_py
node_model_py -->|"encodes"| node_cnn_resnet_py
node_model_py -->|"encodes"| node_cnn_mknet_py
node_model_py -->|"encodes"| node_cnn_vanilla_py
node_detect_py -->|"uses"| node_det_conv_py
node_detect_py -->|"uses"| node_det_attention_py
node_detect_py -->|"uses"| node_det_detr_py
node_detect_py -->|"uses"| node_det_tan_py
node_detect_py -->|"consumes"| node_temporal_py
node_loss_py -->|"supervises"| node_detect_py
node_eval_qhv_py -->|"scores"| node_detect_py

click node_main_py "https://github.com/exmorgan-alter/afafsgd/blob/main/main.py"
click node_warm_up_py "https://github.com/exmorgan-alter/afafsgd/blob/main/warm_up.py"
click node_loss_py "https://github.com/exmorgan-alter/afafsgd/blob/main/loss.py"
click node_utilize_py "https://github.com/exmorgan-alter/afafsgd/blob/main/utilize.py"
click node_qhvdata_py "https://github.com/exmorgan-alter/afafsgd/blob/main/dataset/QHVdata.py"
click node_dataset_base_py "https://github.com/exmorgan-alter/afafsgd/blob/main/dataset/base.py"
click node_model_py "https://github.com/exmorgan-alter/afafsgd/blob/main/model/model.py"
click node_model_base_py "https://github.com/exmorgan-alter/afafsgd/blob/main/model/base.py"
click node_detect_py "https://github.com/exmorgan-alter/afafsgd/blob/main/model/detect.py"
click node_temporal_py "https://github.com/exmorgan-alter/afafsgd/blob/main/model/temporal.py"
click node_cnn_resnet_py "https://github.com/exmorgan-alter/afafsgd/blob/main/model/CNNs/resnet.py"
click node_cnn_mknet_py "https://github.com/exmorgan-alter/afafsgd/blob/main/model/CNNs/mknet.py"
click node_cnn_vanilla_py "https://github.com/exmorgan-alter/afafsgd/blob/main/model/CNNs/vanilla.py"
click node_det_conv_py "https://github.com/exmorgan-alter/afafsgd/blob/main/model/Det/Conv.py"
click node_det_attention_py "https://github.com/exmorgan-alter/afafsgd/blob/main/model/Det/attention.py"
click node_det_detr_py "https://github.com/exmorgan-alter/afafsgd/blob/main/model/Det/detr.py"
click node_det_tan_py "https://github.com/exmorgan-alter/afafsgd/blob/main/model/Det/tan.py"
click node_eval_qhv_py "https://github.com/exmorgan-alter/afafsgd/blob/main/eval/eval_qhv.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_py,node_warm_up_py,node_loss_py,node_utilize_py toneBlue
class node_qhvdata_py,node_dataset_base_py toneAmber
class node_model_py,node_model_base_py,node_detect_py,node_temporal_py,node_cnn_resnet_py,node_cnn_mknet_py,node_cnn_vanilla_py,node_det_conv_py,node_det_attention_py,node_det_detr_py,node_det_tan_py toneMint
class node_eval_qhv_py toneRose
```

## Components

### Training

Entry points, optimization, and shared utilities

- [main.py](https://github.com/exmorgan-alter/afafsgd/blob/main/main.py): entrypoint · Main training and validation driver · `main.py`
- [warm_up.py](https://github.com/exmorgan-alter/afafsgd/blob/main/warm_up.py): schedule · Warmup or early-stage training routine · `warm_up.py`
- [loss.py](https://github.com/exmorgan-alter/afafsgd/blob/main/loss.py): losses · Training objectives for boundary localization · `loss.py`
- [utilize.py](https://github.com/exmorgan-alter/afafsgd/blob/main/utilize.py): helpers · Shared utility functions · `utilize.py`

### Data

Prepared dataset loaders and access layer

- [QHVdata.py](https://github.com/exmorgan-alter/afafsgd/blob/main/dataset/QHVdata.py): dataset loader · QHV-specific prepared data loader · `dataset/QHVdata.py`
- [base.py](https://github.com/exmorgan-alter/afafsgd/blob/main/dataset/base.py): dataset base · Common dataset behavior and shared access logic · `dataset/base.py`

### Model

Encoder, temporal reasoning, and detection stack

- [model.py](https://github.com/exmorgan-alter/afafsgd/blob/main/model/model.py): model wrapper · Top-level model assembly and forward interface · `model/model.py`
- [base.py](https://github.com/exmorgan-alter/afafsgd/blob/main/model/base.py): model base · Shared model components and abstractions · `model/base.py`
- [detect.py](https://github.com/exmorgan-alter/afafsgd/blob/main/model/detect.py): inference · Detection-facing model interface · `model/detect.py`
- [temporal.py](https://github.com/exmorgan-alter/afafsgd/blob/main/model/temporal.py): temporal module · Temporal aggregation and sequence reasoning · `model/temporal.py`
- [resnet.py](https://github.com/exmorgan-alter/afafsgd/blob/main/model/CNNs/resnet.py): cnn encoder · ResNet-based feature encoder · `model/CNNs/resnet.py`
- [mknet.py](https://github.com/exmorgan-alter/afafsgd/blob/main/model/CNNs/mknet.py): cnn encoder · MKNet-style feature encoder · `model/CNNs/mknet.py`
- [vanilla.py](https://github.com/exmorgan-alter/afafsgd/blob/main/model/CNNs/vanilla.py): cnn encoder · Baseline feature encoder · `model/CNNs/vanilla.py`
- [Conv.py](https://github.com/exmorgan-alter/afafsgd/blob/main/model/Det/Conv.py): detector block · Convolutional detection block · `model/Det/Conv.py`
- [attention.py](https://github.com/exmorgan-alter/afafsgd/blob/main/model/Det/attention.py): detector block · Attention-based interaction block · `model/Det/attention.py`
- [detr.py](https://github.com/exmorgan-alter/afafsgd/blob/main/model/Det/detr.py): detector head · DETR-style temporal set prediction · `model/Det/detr.py`
- [tan.py](https://github.com/exmorgan-alter/afafsgd/blob/main/model/Det/tan.py): detector head · Temporal anchor-based localization head · `model/Det/tan.py`

### Evaluation

Benchmark-specific scoring

- [eval_qhv.py](https://github.com/exmorgan-alter/afafsgd/blob/main/eval/eval_qhv.py): evaluation · QHV benchmark metrics and scoring · `eval/eval_qhv.py`

## Connections

- main.py → QHVdata.py: loads · Training and validation data pipeline
- main.py → model.py: runs · Builds and executes the localization model
- main.py → loss.py: optimizes · Applies task losses during training
- main.py → eval_qhv.py: validates · Evaluates predictions on QHV
- main.py → warm_up.py: schedules · Optional warmup phase
- main.py → utilize.py: uses · Logging, device, or checkpoint helpers
- QHVdata.py → base.py: extends · Dataset-specific loader built on shared base behavior
- model.py → base.py: composes · Top-level model relies on shared base abstractions
- model.py → detect.py: exposes · Inference-facing detection interface
- model.py → temporal.py: includes · Temporal reasoning stage
- model.py → resnet.py: encodes · Visual feature extraction option
- model.py → mknet.py: encodes · Alternative visual feature extraction option
- model.py → vanilla.py: encodes · Baseline visual feature extraction option
- detect.py → Conv.py: uses · Convolutional detector processing
- detect.py → attention.py: uses · Attention-based detector interaction
- detect.py → detr.py: uses · DETR-style boundary prediction
- detect.py → tan.py: uses · Anchor-based temporal localization
- detect.py → temporal.py: consumes · Detector consumes temporally aggregated features
- loss.py → detect.py: supervises · Losses are computed from detector outputs
- eval_qhv.py → detect.py: scores · Evaluation consumes predicted moments
