# hanghuacs/finecaption architecture

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

- Interactive diagram: https://gitdiagram.com/hanghuacs/finecaption
- Repository: https://github.com/hanghuacs/finecaption

## Overview

##### Project type and purpose
- Type: Research-focused Vision-Language model with a web demo front-end.
- Purpose:
– Train and evaluate an image-mask-conditional captioning model (FINECAPTION).
– Expose interactive demos via a static website (serving CSS/JS/images) and dataset download.

##### File structure
Top-level:
- Data/CompositionCap.json.zip – Compressed dataset.
- README.md – Project description and setup instructions.
- static/ – All front-end assets:
– css/ (Bulma framework + custom index.css)
– js/ (bulma-carousel.js, bulma-slider.js, index.js)

No server code is visible here, which implies the web demo may be purely static or served by a simple Python/Flask/Node server elsewhere.

##### Extract key architectural insights from the README
- Core functionality: Compositional captioning with arbitrary input masks.
- Mask decoding utility in Python.
- Installation script (init.sh) sets up the modeling environment (likely PyTorch, Transformers, etc.).
- No explicit backend framework listed; assume a minimal REST/HTTP interface for demo inference.

##### Main components
a. Data Layer
– CompositionCap Dataset (Data/CompositionCap.json.zip)
– Preprocessing & Mask-Decoding Module
b. Model Training & Inference Layer
– FINECAPTION training scripts (environment from init.sh)
– Vision-Language model checkpoints (8B parameters)
– Inference API (e.g., Flask or FastAPI service)
c. Frontend Layer
– Static Web Server (e.g., Nginx or GitHub Pages)
– CSS (Bulma + index.css)
– JavaScript (index.js orchestrates carousel, sliders, fetches results)
– Images and videos (teasers, model.pdf)
d. External Services (optional but often present)
– CDN for serving static assets
– GPU Cluster for training/inference
– Logging/Monitoring (e.g., Prometheus/Grafana)

##### Relationships & interactions
- The Frontend issues HTTP requests to the Inference API, sending:
– High-resolution image
– Binary mask (decoded via the Python mask-decoding utility)
- The Inference API loads the fine-tuned model, runs inference, and returns caption text.
- Model Training Pipeline consumes the raw JSON dataset, preprocesses masks, and produces model checkpoints.
- Static assets (HTML/CSS/JS/images) are delivered by the Web Server or CDN directly to the user’s browser.
- Optionally, logs and metrics are pushed from the Inference API to a Monitoring service.

##### Architectural patterns & design principles
- Three-Tier Architecture:
– Presentation (Static Frontend)
– Application (Inference API)
– Data (Dataset + Model Weights)
- Separation of concerns:
– Frontend purely handles UI/UX and visual demos.
– Backend encapsulates all ML logic.
– Data layer isolated for reproducibility.
- Modular Mask Decoding: Utility function independent of core model logic.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Project Overview
    Project["README.md"]:::external

    %% Presentation Layer
    subgraph "Presentation Layer"
        Browser["User Browser"]:::external
        WebServer["Static Web Server\n(Nginx/GitHub Pages)"]:::presentation
        subgraph "Static Assets"
            BulmaCSS["bulma.css.map.txt"]:::presentation
            IndexCSS["index.css"]:::presentation
            CarouselJS["bulma-carousel.js"]:::presentation
            SliderJS["bulma-slider.js"]:::presentation
            IndexJS["index.js"]:::presentation
            ModelPDF["model.pdf"]:::presentation
            SteveVideo["steve.webm"]:::presentation
            TeaserPDF["teaser-1.pdf"]:::presentation
            StackedDir["stacked/"]:::presentation
            IconDir["stacked/Icon/"]:::presentation
        end
    end

    %% Application Layer
    subgraph "Application Layer"
        InferenceAPI["Inference API Service\n(Python, Flask, PyTorch)"]:::application
        MaskDecoding["Mask Decoding Utility\n(Python)"]:::application
        Model["Vision-Language Model Checkpoints\n(8B parameters)"]:::application
        Monitoring["Monitoring Service\n(Prometheus/Grafana)"]:::external
        GPUCluster["GPU Cluster"]:::external
    end

    %% Data Layer
    subgraph "Data Layer"
        Dataset["CompositionCap Dataset"]:::data
        TrainingPipeline["Training Pipeline\n(Offline Batch Job)"]:::application
    end

    %% Data Flows
    Browser -->|Requests static assets| WebServer
    WebServer --> BulmaCSS
    WebServer --> IndexCSS
    WebServer --> CarouselJS
    WebServer --> SliderJS
    WebServer --> IndexJS
    WebServer --> ModelPDF
    WebServer --> SteveVideo
    WebServer --> TeaserPDF
    WebServer --> StackedDir
    WebServer --> IconDir

    IndexJS -->|FetchInference| InferenceAPI
    InferenceAPI -->|DecodeMask| MaskDecoding
    InferenceAPI -->|LoadModel| Model
    InferenceAPI -->|LogMetrics| Monitoring
    InferenceAPI -->|UseGPU| GPUCluster

    TrainingPipeline -->|Consumes| Dataset
    TrainingPipeline -->|Produces| Model

    %% Click Events
    click Project "https://github.com/hanghuacs/finecaption/blob/main/README.md"
    click Dataset "https://github.com/hanghuacs/finecaption/blob/main/Data/CompositionCap.json.zip"
    click BulmaCSS "https://github.com/hanghuacs/finecaption/blob/main/static/css/bulma.css.map.txt"
    click IndexCSS "https://github.com/hanghuacs/finecaption/blob/main/static/css/index.css"
    click CarouselJS "https://github.com/hanghuacs/finecaption/blob/main/static/js/bulma-carousel.js"
    click SliderJS "https://github.com/hanghuacs/finecaption/blob/main/static/js/bulma-slider.js"
    click IndexJS "https://github.com/hanghuacs/finecaption/blob/main/static/js/index.js"
    click ModelPDF "https://github.com/hanghuacs/finecaption/blob/main/static/images/model.pdf"
    click SteveVideo "https://github.com/hanghuacs/finecaption/blob/main/static/images/steve.webm"
    click TeaserPDF "https://github.com/hanghuacs/finecaption/blob/main/static/images/teaser-1.pdf"
    click StackedDir "https://github.com/hanghuacs/finecaption/tree/main/static/interpolation/stacked/"
    click IconDir "https://github.com/hanghuacs/finecaption/tree/main/static/interpolation/stacked/Icon/"

    %% Styling
    classDef presentation fill:#9ad0f5,stroke:#333,stroke-width:1px
    classDef application fill:#9eedac,stroke:#333,stroke-width:1px
    classDef data fill:#f5b97a,stroke:#333,stroke-width:1px
    classDef external fill:#cccccc,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
```
