# oucyy361/ouc-cge architecture

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

- Interactive diagram: https://gitdiagram.com/oucyy361/ouc-cge
- Repository: https://github.com/oucyy361/ouc-cge

## Overview

1. This repository is a video-recognition training/evaluation framework built on Facebook’s SlowFast codebase, adapted for the OUC-CGE classroom group engagement dataset. The core task is clip-level classification from visual input, with labels for high/medium/low engagement.

2. The architecture is organized around a pipeline: dataset manifests and video clips feed a configurable data loader, the loader produces sampled clip tensors, models compute logits, and training/test utilities handle optimization, checkpointing, metrics, and reporting.

3. The dataset boundary is explicit. `train.csv`, `val.csv`, and `test.csv` define the OUC-CGE splits, while `slowfast/datasets/` contains the dataset adapters and video decoding/transformation logic. This layer abstracts away whether the input comes from Kinetics-style datasets or the classroom dataset, so the rest of the stack sees standardized tensors and labels.

4. Data ingestion is handled by `slowfast/datasets/loader.py`, `build.py`, `decoder.py`, and transform modules such as `transform.py`, `cv2_transform.py`, `rand_augment.py`, `mixup.py`, and `random_erasing.py`. This subsystem is responsible for clip sampling, frame decoding, augmentation, and batch assembly, which is the main preprocessing boundary before model execution.

5. Model construction lives in `slowfast/models/`. The repo includes multiple video backbones and heads: SlowFast, Slow, C2D, I3D, X3D, MViT/MViTv2, reversible MViT, plus supporting blocks like stems, residual helpers, non-local blocks, attention, and classification heads. The design is modular: a builder selects a backbone from configuration, and a head converts spatiotemporal features into class predictions.

6. Configuration is centralized in `slowfast/config/` and the many YAML files under `configs/Kinetics/`. These configs define model family, depth, input sampling rate, crop strategy, training schedule, and dataset-specific parameters. The presence of Kinetics-oriented configs indicates the codebase is largely reused from generic action-recognition settings, with OUC-CGE using the same framework but different data manifests.

7. The training/evaluation entrypoints are in `tools/`. `train_net.py` runs the optimization loop, `test_net.py` performs validation/test inference, `run_net.py` is the general launcher, `benchmark.py` measures throughput or runtime, and `demo_net.py`/`visualization.py` support interactive or qualitative inference. These scripts are the operational boundary between the framework and user-facing experiments.

8. Optimization and learning-rate behavior are implemented in `slowfast/models/optimizer.py` and `slowfast/utils/lr_policy.py`, while losses and metric computation are in `slowfast/models/losses.py`, `slowfast/utils/metrics.py`, and `cal_metrics.py`. This is where classification performance is computed and where the project’s reported accuracy results are derived.

9. Experiment management is handled by `slowfast/utils/`. This includes checkpoint save/load, distributed training support, logging, environment setup, multiprocessing, multigrid scheduling, and meter tracking. These utilities make the training pipeline scalable and reproducible across single- and multi-GPU environments.

10. The repo also contains visualization and demo infrastructure in `slowfast/visualization/`, including prediction overlays, Grad-CAM utilities, async prediction, TensorBoard visualization, and AVA-style demo helpers. This subsystem is separate from training: it consumes trained checkpoints and video inputs to inspect model behavior and produce qualitative outputs.

11. The main external boundary is the source dataset: OUC-CGE provides classroom videos and labels, while the codebase inherits action-recognition model families from SlowFast. The README’s reported accuracies compare several of those families on the same dataset, so the repo serves both as a dataset benchmark package and as a reusable video-classification framework.

12. In diagram terms, the key flow is: CSV split files and video clips -> dataset/decoder/augmentation layer -> model builder/backbone/head -> optimizer/loss/metrics -> checkpoints and evaluation outputs, with visualization/demos branching off from trained checkpoints. The main architectural separation is between data preparation, model execution, experiment orchestration, and qualitative analysis.

Main entry points: [`slowfast/config/defaults.py`](https://github.com/oucyy361/ouc-cge/blob/main/slowfast/config/defaults.py) (Config system), [`tools/train_net.py`](https://github.com/oucyy361/ouc-cge/blob/main/tools/train_net.py) (Train), [`tools/test_net.py`](https://github.com/oucyy361/ouc-cge/blob/main/tools/test_net.py) (Test), [`slowfast/datasets/loader.py`](https://github.com/oucyy361/ouc-cge/blob/main/slowfast/datasets/loader.py) (Data loader)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_data["Data pipeline"]
  node_splits["CSV splits<br/>dataset manifests<br/>[train.csv]"]
  node_dataset_adapters["Dataset layer<br/>dataset adapters<br/>[kinetics.py]"]
  node_decode_transform["Decode & aug<br/>sampling/preprocess<br/>[decoder.py]"]
  node_loader["Data loader<br/>batch assembly<br/>[loader.py]"]
end

subgraph group_group_model["Models"]
  node_model_build["Model build<br/>model registry<br/>[build.py]"]
  node_video_backbones["Backbones<br/>video architectures"]
  node_model_blocks["Core blocks<br/>network components<br/>[resnet_helper.py]"]
  node_head_loss_opt["Head/Loss/Opt<br/>prediction training<br/>[head_helper.py]"]
end

subgraph group_group_runtime["Runtime"]
  node_config["Config system<br/>experiment config<br/>[defaults.py]"]
  node_train_net["Train<br/>[train_net.py]"]
  node_test_net["Test<br/>evaluation loop<br/>[test_net.py]"]
  node_run_net["Runner<br/>launcher<br/>[run_net.py]"]
  node_benchmark["Benchmark<br/>throughput tool<br/>[benchmark.py]"]
end

subgraph group_group_ops["Utilities"]
  node_metrics["Metrics<br/>[metrics.py]"]
  node_checkpointing["Checkpoints<br/>state management<br/>[checkpoint.py]"]
  node_runtime_utils["Runtime utils<br/>distributed/logging<br/>[distributed.py]"]
end

subgraph group_group_viz["Visualization"]
  node_visualization["Viz tools<br/>qualitative analysis<br/>[predictor.py]"]
  node_demo_tools["Demo entrypoints<br/>inference demos<br/>[demo_net.py]"]
end

node_splits -->|"define splits"| node_dataset_adapters
node_dataset_adapters -->|"sample clips"| node_decode_transform
node_decode_transform -->|"assemble batches"| node_loader
node_config -->|"select dataset"| node_dataset_adapters
node_config -->|"select model"| node_model_build
node_config -->|"drive run"| node_train_net
node_config -->|"drive eval"| node_test_net
node_config -->|"drive benchmark"| node_benchmark
node_loader -->|"feed batches"| node_train_net
node_loader -->|"feed batches"| node_test_net
node_model_build -->|"instantiate"| node_video_backbones
node_video_backbones -->|"compose blocks"| node_model_blocks
node_video_backbones -->|"emit logits"| node_head_loss_opt
node_head_loss_opt -->|"optimize"| node_train_net
node_train_net -->|"save state"| node_checkpointing
node_test_net -->|"score results"| node_metrics
node_train_net -->|"orchestrate"| node_runtime_utils
node_test_net -->|"orchestrate"| node_runtime_utils
node_benchmark -->|"measure"| node_runtime_utils
node_checkpointing -->|"load weights"| node_visualization
node_visualization -->|"serve demos"| node_demo_tools

click node_splits "https://github.com/oucyy361/ouc-cge/blob/main/train.csv"
click node_dataset_adapters "https://github.com/oucyy361/ouc-cge/blob/main/slowfast/datasets/kinetics.py"
click node_decode_transform "https://github.com/oucyy361/ouc-cge/blob/main/slowfast/datasets/decoder.py"
click node_loader "https://github.com/oucyy361/ouc-cge/blob/main/slowfast/datasets/loader.py"
click node_config "https://github.com/oucyy361/ouc-cge/blob/main/slowfast/config/defaults.py"
click node_train_net "https://github.com/oucyy361/ouc-cge/blob/main/tools/train_net.py"
click node_test_net "https://github.com/oucyy361/ouc-cge/blob/main/tools/test_net.py"
click node_run_net "https://github.com/oucyy361/ouc-cge/blob/main/tools/run_net.py"
click node_benchmark "https://github.com/oucyy361/ouc-cge/blob/main/tools/benchmark.py"
click node_model_build "https://github.com/oucyy361/ouc-cge/blob/main/slowfast/models/build.py"
click node_video_backbones "https://github.com/oucyy361/ouc-cge/blob/main/slowfast/models/video_model_builder.py"
click node_model_blocks "https://github.com/oucyy361/ouc-cge/blob/main/slowfast/models/resnet_helper.py"
click node_head_loss_opt "https://github.com/oucyy361/ouc-cge/blob/main/slowfast/models/head_helper.py"
click node_metrics "https://github.com/oucyy361/ouc-cge/blob/main/slowfast/utils/metrics.py"
click node_checkpointing "https://github.com/oucyy361/ouc-cge/blob/main/slowfast/utils/checkpoint.py"
click node_runtime_utils "https://github.com/oucyy361/ouc-cge/blob/main/slowfast/utils/distributed.py"
click node_visualization "https://github.com/oucyy361/ouc-cge/blob/main/slowfast/visualization/predictor.py"
click node_demo_tools "https://github.com/oucyy361/ouc-cge/blob/main/tools/demo_net.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_splits,node_dataset_adapters,node_decode_transform,node_loader toneBlue
class node_model_build,node_video_backbones,node_model_blocks,node_head_loss_opt toneAmber
class node_config,node_train_net,node_test_net,node_run_net,node_benchmark toneMint
class node_metrics,node_checkpointing,node_runtime_utils toneRose
class node_visualization,node_demo_tools toneIndigo
```

## Components

### Data pipeline

Dataset manifests, decoding, sampling, and augmentation before model execution.

- [CSV splits](https://github.com/oucyy361/ouc-cge/blob/main/train.csv): dataset manifests · Train/val/test split files for the OUC-CGE engagement dataset. · `train.csv`
- [Dataset layer](https://github.com/oucyy361/ouc-cge/blob/main/slowfast/datasets/kinetics.py): dataset adapters · Dataset-specific adapters and loaders for Kinetics, AVA, Charades, SSv2, and the classroom dataset. · `slowfast/datasets/kinetics.py`
- [Decode & aug](https://github.com/oucyy361/ouc-cge/blob/main/slowfast/datasets/decoder.py): sampling/preprocess · Clip sampling, video decoding, transforms, mixup, rand augment, and random erasing. · `slowfast/datasets/decoder.py`
- [Data loader](https://github.com/oucyy361/ouc-cge/blob/main/slowfast/datasets/loader.py): batch assembly · Builds iterable batches from dataset samples and preprocessing pipelines. · `slowfast/datasets/loader.py`

### Models

Video backbones, heads, losses, and optimization components.

- [Model build](https://github.com/oucyy361/ouc-cge/blob/main/slowfast/models/build.py): model registry · Selects and constructs the configured video architecture. · `slowfast/models/build.py`
- [Backbones](https://github.com/oucyy361/ouc-cge/blob/main/slowfast/models/video_model_builder.py): video architectures · SlowFast, Slow, C2D, I3D, X3D, MViT/MViTv2, reversible MViT, and related builders. · `slowfast/models/video_model_builder.py`
- [Core blocks](https://github.com/oucyy361/ouc-cge/blob/main/slowfast/models/resnet_helper.py): network components · Stems, residual helpers, attention, non-local blocks, operators, and shared model utilities. · `slowfast/models/resnet_helper.py`
- [Head/Loss/Opt](https://github.com/oucyy361/ouc-cge/blob/main/slowfast/models/head_helper.py): prediction training · Classification heads, losses, optimizer construction, and learning-rate policy. · `slowfast/models/head_helper.py`

### Runtime

Training, evaluation, benchmarking, and orchestration entrypoints.

- [Config system](https://github.com/oucyy361/ouc-cge/blob/main/slowfast/config/defaults.py): experiment config · Central defaults and custom config extensions plus Kinetics-oriented YAML recipes. · `slowfast/config/defaults.py`
- [Train](https://github.com/oucyy361/ouc-cge/blob/main/tools/train_net.py): training loop · Main optimization entrypoint for supervised video classification. · `tools/train_net.py`
- [Test](https://github.com/oucyy361/ouc-cge/blob/main/tools/test_net.py): evaluation loop · Validation and test-time inference entrypoint. · `tools/test_net.py`
- [Runner](https://github.com/oucyy361/ouc-cge/blob/main/tools/run_net.py): launcher · General experiment launcher that wires config, data, model, and runtime components. · `tools/run_net.py`
- [Benchmark](https://github.com/oucyy361/ouc-cge/blob/main/tools/benchmark.py): throughput tool · Measures runtime or input pipeline performance. · `tools/benchmark.py`

### Utilities

Shared infrastructure for checkpoints, distributed execution, logging, and metrics.

- [Metrics](https://github.com/oucyy361/ouc-cge/blob/main/slowfast/utils/metrics.py): evaluation metrics · Accuracy and reporting utilities, including dataset-specific metric computation. · `slowfast/utils/metrics.py`
- [Checkpoints](https://github.com/oucyy361/ouc-cge/blob/main/slowfast/utils/checkpoint.py): state management · Save/load model states and restore experiment progress. · `slowfast/utils/checkpoint.py`
- [Runtime utils](https://github.com/oucyy361/ouc-cge/blob/main/slowfast/utils/distributed.py): distributed/logging · Distributed execution, environment setup, logging, multiprocessing, meters, and multigrid support. · `slowfast/utils/distributed.py`

### Visualization

Qualitative inference, CAMs, and demo tooling built on trained checkpoints.

- [Viz tools](https://github.com/oucyy361/ouc-cge/blob/main/slowfast/visualization/predictor.py): qualitative analysis · Prediction overlays, Grad-CAM, async predictors, demo loaders, and TensorBoard visualization. · `slowfast/visualization/predictor.py`
- [Demo entrypoints](https://github.com/oucyy361/ouc-cge/blob/main/tools/demo_net.py): inference demos · User-facing demo and visualization scripts that consume trained checkpoints and video inputs. · `tools/demo_net.py`

## Connections

- CSV splits → Dataset layer: define splits · CSV manifests specify the dataset partitions consumed by adapters.
- Dataset layer → Decode & aug: sample clips · Dataset adapters request frame decoding and preprocessing.
- Decode & aug → Data loader: assemble batches · Transformed samples are packaged into minibatches.
- Config system → Dataset layer: select dataset · Configuration chooses the dataset implementation and input settings.
- Config system → Model build: select model · Configuration determines the backbone family and head behavior.
- Config system → Train: drive run · Training entrypoint consumes experiment configuration.
- Config system → Test: drive eval · Evaluation entrypoint consumes experiment configuration.
- Config system → Benchmark: drive benchmark · Benchmarking uses the same experiment settings.
- Data loader → Train: feed batches · Training consumes sampled clip tensors and labels.
- Data loader → Test: feed batches · Evaluation consumes the same standardized batches.
- Model build → Backbones: instantiate · The builder selects a specific video architecture.
- Backbones → Core blocks: compose blocks · Backbones are assembled from reusable stems, residual, and attention components.
- Backbones → Head/Loss/Opt: emit logits · Backbones connect to task heads for classification outputs.
- Head/Loss/Opt → Train: optimize · Training uses the head, loss, optimizer, and LR policy.
- Train → Checkpoints: save state · Training writes checkpoints for recovery and later inference.
- Test → Metrics: score results · Evaluation computes reported accuracy and other metrics.
- Train → Runtime utils: orchestrate · Training relies on distributed, logging, and meter utilities.
- Test → Runtime utils: orchestrate · Evaluation reuses the shared runtime infrastructure.
- Benchmark → Runtime utils: measure · Benchmarking exercises the same execution scaffolding.
- Checkpoints → Viz tools: load weights · Visualization and demos consume trained checkpoints.
- Viz tools → Demo entrypoints: serve demos · Visualization components back the demo entrypoints.
