# totuanan/aicitychallenge2024_track2 architecture

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

- Interactive diagram: https://gitdiagram.com/totuanan/aicitychallenge2024_track2
- Repository: https://github.com/totuanan/aicitychallenge2024_track2

## Overview

##### Project Type and Purpose
- This project is a research-oriented multi-component video description and captioning system (aimed at the AI City Challenge). It is designed to convert raw traffic videos into descriptive captions by combining multiple views and refining the captioning process.
- The system supports a “single-view” pipeline for processing videos (with preprocessing, feature extraction, inference, and training) and also branches into “motion-blur” and multi-view methodologies (integrated via external repositories like LLaVA and modules in ‘internvid’).

##### Analyzing the File Structure for Architectural Clues
- There are clear separations across components:
– Data Ingestion and Preprocessing: Scripts like bdd5k2youcook.py, wts2youcook_by_phase.py and directories such as “analysis” and “feat_extractor” indicate a dedicated preprocessing layer that converts raw videos and associated captions to the required ‘YouCook’ format.
– Feature Extraction: The “feat_extractor/extract” and “feat_extractor/transform” directories house modules that generate feature representations from videos (e.g., CSV construction, loading videos, merging features).
– Core Model Pipelines: The “vid2seq” directory (with its configuration, training, module implementations, and inference scripts) encapsulates the main video-to-sequence modeling pipeline. Similarly, the “internvid” directory provides modules, dataloaders, and evaluation scripts for fine-tuning and retrieval tasks.
– Multi-view and Motion-Blur Extensions: Additional components for multi-view processing (“multiview/LLaVA”) and specialized handling of motion blur (“motion_blur”) are provided, each with their own README and supporting scripts.
– Supporting Modules and Third-Party Integrations: Many directories (like various “clip_*” modules under internvid/modules) indicate the incorporation of pretrained vision-language models and transformers, which are essential for captioning and multimodal encoding.
– Orchestration and Utility Scripts: The “scripts” folder (containing multiple shell scripts for training, inference, and generating submissions), notebooks for experiments, and a consolidated “requirements.txt” show the overall orchestration and dependency management for the system.

a. Main Components:
– Data Ingestion & Preprocessing: Represent raw video and caption inputs being converted (using scripts like bdd5k2youcook_by_phase.py and wts2youcook_by_phase.py) into the standardized format.
– Feature Extraction Module: Illustrate the role of the “feat_extractor” components that generate CSV files (video path, feature path pairs) and perform video loading, preprocessing, and feature merging.
– Core Modeling Pipelines:
- Single-View Pipeline (vid2seq): Show how extracted features are fed into the video-to-sequence (captioning) pipeline with training (notebooks, train.py, etc.), inference (infer.py, notebooks/vid2seq_inference.ipynb), and submission generation (scripts/get_submission.sh).
- Internvid Module: Capture the responsibilities of dataloaders, various retrieval tasks, and fine-tuning scripts.
- Motion-Blur Processing: Indicate a parallel pipeline for handling motion blur issues (motion_blur directory with submodules for image captioning and BLIP2 integrations).
- Multi-View Comments: Highlight the “multiview/LLaVA” component, which supports multi-modal processing with its robust set of training, evaluation, and serving modules.
– Evaluation and Analysis: Use components such as “analysis” scripts and evaluation notebooks within internvid, showing how results are evaluated, visualized, and fed back into system improvements.

b. Relationships and Data Flow:
– Start with raw video and caption data (with the formats defined in the README) entering the system.
– Next, direct output flows into the Feature Extraction module (which outputs CSV files linking video paths to extracted features).

c. Architectural Patterns and Technologies:
– Highlight that the design follows a modular pattern where preprocessing, feature extraction, and model training/inference are decoupled, allowing independent experimentation.
– Mention the use of containerized and isolated environments (e.g., virtualenv) as seen in the setup instructions.
– Include references to key libraries/frameworks implied by components (e.g., usage of CLIP models, transformer modules, and potential PyTorch/NumPy in the extract and modeling modules).

d. Tailor to the Project Type:
– For a full-stack research application like this, emphasize the separation between data preparation, feature extraction, and multiple model training/inference pipelines.

- External integrations (e.g., pre-trained models from “clip_*” modules) and note the usage of notebooks and shell scripts for orchestration.

##### Final Advice
- Be very detailed: Do not hesitate to “over-segment” the system into as many logical components as possible.

## Diagram (Mermaid)

```mermaid
graph TD
    A("Raw Video & Captions"):::raw

    subgraph "Data Ingestion & Preprocessing"
        B1("bdd5k2youcook.py"):::ingestion
        B2("wts2youcook.py"):::ingestion
        B3("wts2youcook_test.py"):::ingestion
        B4("internvid/preprocess"):::ingestion
    end

    subgraph "Feature Extraction"
        C1("feat_extractor/extract"):::extraction
        C2("feat_extractor/transform"):::extraction
    end

    subgraph "Core Modeling Pipelines"
        subgraph "Single-View Pipeline"
            D1("vid2seq"):::pipeline
            D2("notebooks/vid2seq_inference.ipynb"):::pipeline
        end
        subgraph "Internvid Modules"
            E1("internvid"):::pipeline
        end
        subgraph "Motion-Blur Processing"
            F1("motion_blur"):::pipeline
        end
        subgraph "Multi-View Processing"
            G1("multiview/LLaVA"):::pipeline
        end
    end

    subgraph "Evaluation & Analysis"
        H1("analysis"):::eval
    end

    subgraph "Orchestration & Utility Scripts"
        I1("scripts"):::utility
        I2("download_model.py"):::utility
        I3("ensembler.py"):::utility
    end

    %% Data Flow Connections
    A --> B1
    B1 --> B2
    B2 --> B3
    B3 --> B4
    B4 --> C1
    C1 --> C2
    C2 --> D1
    C2 --> E1
    C2 --> F1
    C2 --> G1
    D1 --> D2
    D2 --> H1
    E1 --> H1
    F1 --> H1
    G1 --> H1
    H1 --> I1
    I1 --> I2
    I1 --> I3
    %% Feedback Loop from Evaluation back to Ingestion
    H1 -.-> B1

    %% Click Events
    click B1 "https://github.com/totuanan/aicitychallenge2024_track2/blob/main/bdd5k2youcook.py"
    click B2 "https://github.com/totuanan/aicitychallenge2024_track2/blob/main/wts2youcook.py"
    click B3 "https://github.com/totuanan/aicitychallenge2024_track2/blob/main/wts2youcook_test.py"
    click B4 "https://github.com/totuanan/aicitychallenge2024_track2/tree/main/internvid/preprocess"
    click C1 "https://github.com/totuanan/aicitychallenge2024_track2/tree/main/feat_extractor/extract"
    click C2 "https://github.com/totuanan/aicitychallenge2024_track2/tree/main/feat_extractor/transform"
    click D1 "https://github.com/totuanan/aicitychallenge2024_track2/tree/main/vid2seq"
    click D2 "https://github.com/totuanan/aicitychallenge2024_track2/blob/main/notebooks/vid2seq_inference.ipynb"
    click E1 "https://github.com/totuanan/aicitychallenge2024_track2/tree/main/internvid"
    click F1 "https://github.com/totuanan/aicitychallenge2024_track2/tree/main/motion_blur"
    click G1 "https://github.com/totuanan/aicitychallenge2024_track2/tree/main/multiview/LLaVA"
    click H1 "https://github.com/totuanan/aicitychallenge2024_track2/tree/main/analysis"
    click I1 "https://github.com/totuanan/aicitychallenge2024_track2/tree/main/scripts"
    click I2 "https://github.com/totuanan/aicitychallenge2024_track2/blob/main/download_model.py"
    click I3 "https://github.com/totuanan/aicitychallenge2024_track2/blob/main/ensembler.py"

    %% Styles
    classDef raw fill:#E6E6FA,stroke:#000,stroke-width:2px,color:#000
    classDef ingestion fill:#ADD8E6,stroke:#000,stroke-width:2px,color:#000
    classDef extraction fill:#90EE90,stroke:#000,stroke-width:2px,color:#000
    classDef pipeline fill:#FFB6C1,stroke:#000,stroke-width:2px,color:#000
    classDef eval fill:#FFD700,stroke:#000,stroke-width:2px,color:#000
    classDef utility fill:#D3D3D3,stroke:#000,stroke-width:2px,color:#000
```
