Skip to content
rawcdrPublic

About

CTAD++ (Causal Temporal Action Detection++) is a multi-modal deep learning framework for video-based human action recognition, combining RGB, optical flow, and pose using Cross-Modal Causal Attention (CMCA).

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

CTAD++ — Causal Temporal Action Detection++

CTAD++ (Causal Temporal Action Detection++) is a multi-modal deep learning system for human action recognition on the JHMDB dataset (21 classes), fusing RGB, optical flow, and pose via Cross-Modal Causal Attention (CMCA) within a causal temporal architecture.

Designed as an end-to-end pipeline, it simultaneously performs action classification, spatial localization, and temporal prediction, while leveraging uncertainty estimation to produce reliable, confidence-aware outputs.

Note: Trained weights (.pth), JHMDB videos, and the MediaPipe pose model are not included in this repository (see .gitignore). After cloning, you must prepare the data and run training before evaluation or inference will work.


Prerequisites

  • OS: Windows 10/11 or Linux
  • Python: 3.10+
  • GPU: NVIDIA GPU + CUDA strongly recommended (training on CPU is impractical)
  • Disk: ~5 GB+ for videos/cache/checkpoints (videos are the largest part)

Step-by-step setup & training

Step 1 — Clone and install dependencies

cd path\to\PROJECT

python -m venv .venv
.\.venv\Scripts\Activate.ps1          # Linux/macOS: source .venv/bin/activate
python -m pip install --upgrade pip

# Install PyTorch for your CUDA version: https://pytorch.org
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu124

pip install -r requirements.txt
pip install -e .

Sanity check:

python -c "from ctad.config import config; print('videos:', config.JHMDB_VIDEOS_DIR)"

Step 2 — Prepare JHMDB data

  1. Download / extract JHMDB clips as MP4 files.

  2. Place them under:

    data/videos/<action_name>/<clip_id>.mp4
    

    (21 action folders, e.g. data/videos/golf/...)

  3. Ensure these repo files are present (they are tracked in git):

    • data/jhmdb/splits/train.csv, test.csv
    • data/jhmdb/JHMDB-GT.pkl
  4. Optional quick test clip: data/samples/golf.mp4 (small demo; other samples may be local-only).

See data/README.md for layout details.


Step 3 — Download the pose model

The pose stream needs MediaPipe’s heavy landmarker (not in git):

  1. Download pose_landmarker_heavy.task from MediaPipe Pose Landmarker.

  2. Save it as:

    assets/pose_landmarker_heavy.task
    

See assets/README.md.


Step 4 — Train stage 1 (feature cache + 120 epochs)

This builds the feature cache and saves the stage-1 checkpoint. Expect several hours on a GPU.

# Recommended: train on official train.csv only (no test leakage)
$env:CTAD_TRAINING_SPLIT = "official"    # default if unset

python scripts/train.py

Outputs:

  • outputs/feature_cache/feature_cache_224x16_v3_uniform_sampling/
  • outputs/checkpoints/jhmdb_cmca.pth

Step 5 — Fine-tune stage 2 (40 epochs)

python scripts/finetune.py

Output: outputs/checkpoints/jhmdb_cmca_finetuned.pth (used by default for eval/infer)

Verify:

python -c "from ctad.config import config; import os; print(os.path.isfile(config.checkpoint_path('jhmdb_cmca_finetuned.pth')))"

Should print True.


Step 6 — Evaluate and run inference

After training, run metrics and demos:

# Official test split + confusion matrix
python scripts/evaluate.py --split test --plot-confusion

# Compare stage-1 vs finetuned
python scripts/compare_checkpoints.py

# Single video (use any MP4 you have)
python scripts/infer.py --video data\samples\golf.mp4

# Or run the full post-training pipeline (eval/plots/report; no training)
python scripts/run_pipeline.py

Results go under outputs/results/ and outputs/figures/.


Step 7 — Ablation study (optional, very long)

Train all five variants (GPU, many hours):

python scripts/ablation.py --variants 1,2,3,4,5 --epochs 120

Then evaluate on the official test split (uses saved variant_*.pth, no extra training):

python scripts/evaluate_ablation.py
python scripts/plot_ablation.py
Variant Description
V1 — RGB Baseline ResNet-50 frames only, standard Transformer encoder. No optical flow, pose, CMCA, or causal temporal stack.
V2 — Late Concatenation RGB + motion (flow CNN) + pose fused by concatenation, then a standard Transformer. Multimodal but no cross-modal attention and no causal temporal blocks.
V3 — CMCA + Causal (proposed) Full CTAD: cross-modal fusion (CMCA), causal + anti-causal temporal attention, uncertainty head, bbox and temporal auxiliary heads.
V4 — No Uncertainty Same as V3 but uses a deterministic classifier (no MC-dropout epistemic branch). Tests the value of uncertainty estimation.
V5 — No Skeleton Same as V3 without the pose stream (RGB + motion only). Tests whether skeleton landmarks help beyond appearance and flow.

Weights after training: outputs/ablation/variant_1.pth … variant_5.pth


What you get after training

Path Description
outputs/checkpoints/jhmdb_cmca.pth Stage-1 best weights
outputs/checkpoints/jhmdb_cmca_finetuned.pth Stage-2 weights (default for scripts)
outputs/feature_cache/... Precomputed RGB / flow / pose .npy per clip
outputs/results/eval_test.json Test metrics (after evaluate.py)
outputs/figures/ Confusion matrix, ablation plots, etc.

More detail: docs/CHECKPOINTS.md


Repository layout

PROJECT/
├── src/ctad/              # Package (models, data, training, inference, eval)
├── scripts/               # CLI entry points
├── tests/                 # Smoke tests (pytest)
├── configs/default.yaml   # Reference hyperparameters (runtime: config.py)
├── data/
│   ├── videos/            # JHMDB MP4s (you provide; not in git)
│   ├── jhmdb/splits/      # train.csv, test.csv (in git)
│   └── samples/           # Demo clips (golf.mp4 in git)
├── assets/                # pose_landmarker_heavy.task (you download)
├── outputs/               # Created when you train (gitignored)
└── docs/
    ├── RUN.md
    ├── METHODOLOGY.md
    └── CHECKPOINTS.md

Scripts reference

Script When to use
train.py Required — stage 1 training
finetune.py Required — stage 2 fine-tuning
evaluate.py After training — test/train metrics
infer.py After training — one video + annotated MP4
batch_infer.py After training — many videos
run_pipeline.py After training — eval, plots, report (no training unless --train)
compare_checkpoints.py After training — stage-1 vs finetuned on test
evaluate_ablation.py After ablation weights exist
ablation.py Optional — train V1–V5 (hours)
plot_ablation.py / plot_confusion.py After eval — figures
generate_report.py Writes docs/PROJECT_STATUS.md

Full runbook: docs/RUN.md


Tests

pip install pytest
pytest tests/ -q

Git — what is / is not in the repo

In git Not in git (you provide locally)
Source, scripts, docs, CSV splits, JHMDB-GT.pkl data/videos/, outputs/, *.pth
data/samples/golf.mp4 Large sample MP4s, pose .task file

See .gitignore.


Documentation


Cleanup

Safe to delete to save disk: jhmdb-gulprgb/gulp_rgb/, jhmdb-gulprgb/.cache/ (see jhmdb-gulprgb/README.md).

About

CTAD++ (Causal Temporal Action Detection++) is a multi-modal deep learning framework for video-based human action recognition, combining RGB, optical flow, and pose using Cross-Modal Causal Attention (CMCA).

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages