# chenhaoxing/demamba architecture

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

- Interactive diagram: https://gitdiagram.com/chenhaoxing/demamba
- Repository: https://github.com/chenhaoxing/demamba

## Overview

DeMamba is a research codebase for detecting AI-generated videos, with GenVideo as its benchmark. The intended workflow is to prepare video-derived data, load it for training or evaluation, and classify videos using DeMamba or alternative detectors. The README documents preprocessing and the detection framework; sampled code shows video frame extraction, evaluation behavior, and selected model internals. Training and data-loading connections are not fully evidenced in the excerpts, so those links are marked unverified.

Main entry points: [`train.py`](https://github.com/chenhaoxing/demamba/blob/main/train.py) (Model training), [`dataloader.py`](https://github.com/chenhaoxing/demamba/blob/main/dataloader.py) (Video data loading), [`models/DeMamba.py`](https://github.com/chenhaoxing/demamba/blob/main/models/DeMamba.py) (DeMamba detector), [`util.py`](https://github.com/chenhaoxing/demamba/blob/main/util.py) (Evaluation metrics)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_prep["Data preparation"]
  node_frame_extract["Frame extraction<br/>[video2frame.py]"]
  node_compression["Video compression<br/>[compress.py]"]
  node_csv_lists["CSV lists<br/>[folder2csv.py]"]
end

subgraph group_workflow["Training and evaluation"]
  node_data_loader["Video data loading<br/>[dataloader.py]"]
  node_training["Model training<br/>[train.py]"]
  node_evaluation["Evaluation metrics<br/>[util.py]"]
end

subgraph group_detectors["Video detectors"]
  node_demamba["DeMamba detector<br/>[DeMamba.py]"]
  node_alternative_models["Alternative detectors"]
  node_tall["TALL Swin<br/>[TALL.py]"]
  node_stil["STIL detector<br/>[STIL.py]"]
  node_f3net["F3Net detector<br/>[F3Net.py]"]
  node_npr["NPR detector<br/>[NPR.py]"]
end

subgraph group_internals["Model internals"]
  node_clip_loader["CLIP loading<br/>[clip.py]"]
  node_clip_network["CLIP network<br/>[model.py]"]
  node_clip_tokenizer["CLIP tokenizer"]
  node_mamba["Mamba sequence blocks<br/>[mamba_base.py]"]
  node_parallel_scan["Parallel scan<br/>[pscan.py]"]
end

node_researcher(("Dataset user"))
node_video[("Source videos")]
node_predictions["Video predictions"]

node_researcher -->|"provides"| node_video
node_video -->|"extracts frames"| node_frame_extract
node_researcher -.->|"prepares videos"| node_compression
node_researcher -->|"creates data lists"| node_csv_lists
node_frame_extract -.->|"supplies frames"| node_data_loader
node_csv_lists -.->|"supplies lists"| node_data_loader
node_data_loader -.->|"feeds batches"| node_training
node_training -.->|"trains detector"| node_demamba
node_training -.->|"selects detector"| node_alternative_models
node_training -.->|"selects detector"| node_tall
node_training -.->|"selects detector"| node_stil
node_training -.->|"selects detector"| node_f3net
node_training -.->|"selects detector"| node_npr
node_evaluation -->|"reports predictions"| node_predictions
node_evaluation -.->|"evaluates model"| node_demamba
node_demamba -.->|"uses blocks"| node_mamba
node_clip_loader -->|"builds network"| node_clip_network
node_clip_loader -->|"uses tokenizer"| node_clip_tokenizer
node_mamba -->|"imports scan"| node_parallel_scan

click node_frame_extract "https://github.com/chenhaoxing/demamba/blob/main/Preprocess/video2frame.py"
click node_compression "https://github.com/chenhaoxing/demamba/blob/main/Preprocess/compress.py"
click node_csv_lists "https://github.com/chenhaoxing/demamba/blob/main/Preprocess/folder2csv.py"
click node_data_loader "https://github.com/chenhaoxing/demamba/blob/main/dataloader.py"
click node_training "https://github.com/chenhaoxing/demamba/blob/main/train.py"
click node_evaluation "https://github.com/chenhaoxing/demamba/blob/main/util.py"
click node_demamba "https://github.com/chenhaoxing/demamba/blob/main/models/DeMamba.py"
click node_alternative_models "https://github.com/chenhaoxing/demamba/tree/main/models"
click node_tall "https://github.com/chenhaoxing/demamba/blob/main/models/TALL.py"
click node_stil "https://github.com/chenhaoxing/demamba/blob/main/models/STIL.py"
click node_f3net "https://github.com/chenhaoxing/demamba/blob/main/models/F3Net.py"
click node_npr "https://github.com/chenhaoxing/demamba/blob/main/models/NPR.py"
click node_clip_loader "https://github.com/chenhaoxing/demamba/blob/main/models/clip/clip.py"
click node_clip_network "https://github.com/chenhaoxing/demamba/blob/main/models/clip/model.py"
click node_clip_tokenizer "https://github.com/chenhaoxing/demamba/blob/main/models/clip/simple_tokenizer.py"
click node_mamba "https://github.com/chenhaoxing/demamba/blob/main/models/mamba_base.py"
click node_parallel_scan "https://github.com/chenhaoxing/demamba/blob/main/models/pscan.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_frame_extract,node_compression,node_csv_lists,node_researcher toneBlue
class node_data_loader,node_training,node_evaluation,node_video toneAmber
class node_demamba,node_alternative_models,node_tall,node_stil,node_f3net,node_npr toneMint
class node_clip_loader,node_clip_network,node_clip_tokenizer,node_mamba,node_parallel_scan toneRose
class node_predictions toneIndigo
```

## Components

### Data preparation

- [Frame extraction](https://github.com/chenhaoxing/demamba/blob/main/Preprocess/video2frame.py): `Preprocess/video2frame.py`
- [Video compression](https://github.com/chenhaoxing/demamba/blob/main/Preprocess/compress.py): `Preprocess/compress.py`
- [CSV lists](https://github.com/chenhaoxing/demamba/blob/main/Preprocess/folder2csv.py): `Preprocess/folder2csv.py`

### Training and evaluation

- [Video data loading](https://github.com/chenhaoxing/demamba/blob/main/dataloader.py): `dataloader.py`
- [Model training](https://github.com/chenhaoxing/demamba/blob/main/train.py): `train.py`
- [Evaluation metrics](https://github.com/chenhaoxing/demamba/blob/main/util.py): `util.py`

### Video detectors

- [DeMamba detector](https://github.com/chenhaoxing/demamba/blob/main/models/DeMamba.py): `models/DeMamba.py`
- [Alternative detectors](https://github.com/chenhaoxing/demamba/tree/main/models): `models`
- [TALL Swin](https://github.com/chenhaoxing/demamba/blob/main/models/TALL.py): `models/TALL.py`
- [STIL detector](https://github.com/chenhaoxing/demamba/blob/main/models/STIL.py): `models/STIL.py`
- [F3Net detector](https://github.com/chenhaoxing/demamba/blob/main/models/F3Net.py): `models/F3Net.py`
- [NPR detector](https://github.com/chenhaoxing/demamba/blob/main/models/NPR.py): `models/NPR.py`

### Model internals

- [CLIP loading](https://github.com/chenhaoxing/demamba/blob/main/models/clip/clip.py): `models/clip/clip.py`
- [CLIP network](https://github.com/chenhaoxing/demamba/blob/main/models/clip/model.py): `models/clip/model.py`
- [CLIP tokenizer](https://github.com/chenhaoxing/demamba/blob/main/models/clip/simple_tokenizer.py): `models/clip/simple_tokenizer.py`
- [Mamba sequence blocks](https://github.com/chenhaoxing/demamba/blob/main/models/mamba_base.py): `models/mamba_base.py`
- [Parallel scan](https://github.com/chenhaoxing/demamba/blob/main/models/pscan.py): `models/pscan.py`

### Other components

- **Dataset user**
- **Source videos**
- **Video predictions**

## Connections

- Dataset user → Source videos: provides (evidence: `README.md`)
- Source videos → Frame extraction: extracts frames (evidence: `Preprocess/video2frame.py`)
- Dataset user → Video compression: prepares videos
- Dataset user → CSV lists: creates data lists (evidence: `README.md`)
- Frame extraction → Video data loading: supplies frames
- CSV lists → Video data loading: supplies lists
- Video data loading → Model training: feeds batches
- Model training → DeMamba detector: trains detector
- Model training → Alternative detectors: selects detector
- Model training → TALL Swin: selects detector
- Model training → STIL detector: selects detector
- Model training → F3Net detector: selects detector
- Model training → NPR detector: selects detector
- Evaluation metrics → Video predictions: reports predictions (evidence: `util.py`)
- Evaluation metrics → DeMamba detector: evaluates model
- DeMamba detector → Mamba sequence blocks: uses blocks
- CLIP loading → CLIP network: builds network (evidence: `models/clip/clip.py`)
- CLIP loading → CLIP tokenizer: uses tokenizer (evidence: `models/clip/clip.py`)
- Mamba sequence blocks → Parallel scan: imports scan (evidence: `models/mamba_base.py`)
