# tapaskumardutta1/sketchfusion architecture

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

- Interactive diagram: https://gitdiagram.com/tapaskumardutta1/sketchfusion
- Repository: https://github.com/tapaskumardutta1/sketchfusion

## Overview

##### Project Type and Purpose
- SketchFusion is a computer vision research project that fuses foundation models – specifically, the semantic strength of CLIP and the generative and denoising power of Stable Diffusion – to better understand and process abstract sketch inputs. The goal is to improve tasks like sketch retrieval, recognition, segmentation, and correspondence by compensating for the weaknesses of individual models.
- The README emphasizes its CVPR 2025 publication, multiple evaluation benchmarks, and integration with other repositories (CLIP, DIFT, Geo-Aware). This confirms that the system is a research-oriented, experimentation-heavy full-stack model training/inference pipeline for sketch understanding.

##### Analyzing the File Structure
- Key top-level items: LICENSE, README.md, and setup scripts (prepare_dataset.py, setup.sh) are at the root.
- The main source code is under the src directory. Notice two main subdirectories:
– src/CLIP: Contains code for handling CLIP (e.g., clip.py, model.py, tokenizer) which supplies the semantic features.
– src/SD_CLIP: Contains training scripts (pck_train_combined.py), configuration files (configs/train_sketch.yaml), utilities, and model utilities (for resnet, projection network, and correspondence models). This part is responsible for blending SD’s capabilities with CLIP’s semantic features.

##### Key Architectural Components
a. Data and Configuration:
- Input data such as sketch images (datasets mentioned in the README).
- Preprocessing/utilities code (prepare_dataset.py, and utils in SD_CLIP for datasets and losses).
- YAML configuration file (train_sketch.yaml) which drives training parameters.

b. Foundation Model Modules:
- CLIP Module: Under src/CLIP/clip, responsible for tokenization and semantic feature extraction.
- Stable Diffusion (SD) Module: Implied through SD_CLIP integration (the “denoising” process) even if the actual SD network is part of a pre-trained pipeline.
- Fusion/Projection Networks: Found in src/SD_CLIP/model_utils where modules like projection_network.py and corr_map_model.py help integrate features from both modalities.

c. Training and Integration Layer:
- The training or pipeline orchestrator is found in pck_train_combined.py within SD_CLIP, which dynamically injects CLIP features into the SD denoising process.
- This part handles adaptive feature aggregation (linking to the projector networks and intermediate losses defined in utils).

d. Output/Task-Specific Modules:
- Although the code may not create distinct components for each task, the README shows outputs for segmentation, retrieval, recognition, and correspondence. Represent these as results produced by the fusion of models.

##### Relationships and Interactions
- Then branch out to two parallel pipelines:
- These pipelines then converge at the fusion layer (projection_network, correspondence models) where features are injected and adaptively aggregated.

##### Architectural Patterns/Design Principles
- Modularity by showing separable, clearly labeled modules (data, CLIP, SD, fusion, outputs).
- Integration mechanism – the injection of CLIP features into SD’s process – to point out dynamic feature fusion.
- Mention that the code builds on external projects so you may add notes or external dependency nodes (like “Based on OpenAI CLIP”, “Inspired by DIFT and Geo-Aware-SC”).

##### Final Advice
- Labels and annotations should explain the role of each module in a few words (for instance, “CLIP: Extracts semantic features from sketches”, “SD: Performs denoising with spatial frequency focus”, “Projection Network: Aligns and integrates features”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Input
    Input["Sketch Input"]:::input

    %% Data & Configuration Layer
    subgraph "Data & Configuration"
        DS1["prepare_dataset.py"]:::config
        DS2["YAML Config"]:::config
        DS3["Dataset Utilities"]:::config
    end
    PreProc["Preprocessed Data"]:::config

    %% Foundation Models Layer
    subgraph "Foundation Models"
        subgraph "CLIP Module"
            CLIP1["clip.py"]:::foundation
            CLIP2["model.py"]:::foundation
            CLIP3["simple_tokenizer.py"]:::foundation
        end
        CLIP_A["CLIP Features"]:::foundation
        SDMod["Stable Diffusion Module"]:::foundation
    end

    %% Fusion & Projection Networks Layer
    subgraph "Fusion & Projection Networks"
        Fusion1["Projection Network"]:::fusion
        Fusion2["Correspondence Model"]:::fusion
        Fusion3["ResNet"]:::fusion
        Fused["Fused Features"]:::fusion
    end

    %% Training & Integration Layer
    subgraph "Training & Integration"
        Train["Training Orchestrator"]:::training
    end

    %% General Utilities Layer
    subgraph "General Utilities"
        Loss["Loss Functions"]:::utilities
        CorrUtils["Correspondence Utilities"]:::utilities
        SDUtils["SD_CLIP Utilities"]:::utilities
    end

    %% Task-specific Outputs Layer
    Output["Task-specific Outputs (Recognition,Segmentation,Retrieval,Correspondence)"]:::output

    %% Visual Assets
    VA["Visual Assets"]:::visuals

    %% Connections
    Input --> PreProc
    DS1 --> PreProc
    DS2 --> PreProc
    DS3 --> PreProc

    PreProc --> CLIP_A
    PreProc --> SDMod

    %% Within CLIP subgraph aggregation
    CLIP1 --> CLIP_A
    CLIP2 --> CLIP_A
    CLIP3 --> CLIP_A

    %% Fusion: merging features from both models
    CLIP_A --> Fusion1
    SDMod --> Fusion1

    Fusion1 --> Fused
    Fusion2 --> Fused
    Fusion3 --> Fused

    %% Training and integration flow
    Fused --> Train
    DS2 ---|config| Train
    Loss --- Train
    CorrUtils --- Train
    SDUtils --- Train

    Train --> Output
    Train --- VA

    %% Click Events for Data & Configuration
    click DS1 "https://github.com/tapaskumardutta1/sketchfusion/blob/main/prepare_dataset.py"
    click DS2 "https://github.com/tapaskumardutta1/sketchfusion/blob/main/src/SD_CLIP/configs/train_sketch.yaml"
    click DS3 "https://github.com/tapaskumardutta1/sketchfusion/blob/main/src/SD_CLIP/utils/utils_dataset.py"

    %% Click Events for CLIP Module
    click CLIP1 "https://github.com/tapaskumardutta1/sketchfusion/blob/main/src/CLIP/clip/clip.py"
    click CLIP2 "https://github.com/tapaskumardutta1/sketchfusion/blob/main/src/CLIP/clip/model.py"
    click CLIP3 "https://github.com/tapaskumardutta1/sketchfusion/blob/main/src/CLIP/clip/simple_tokenizer.py"

    %% Click Event for Stable Diffusion Module
    click SDMod "https://github.com/tapaskumardutta1/sketchfusion/tree/main/src/SD_CLIP"

    %% Click Events for Fusion/Projection Networks
    click Fusion1 "https://github.com/tapaskumardutta1/sketchfusion/blob/main/src/SD_CLIP/model_utils/projection_network.py"
    click Fusion2 "https://github.com/tapaskumardutta1/sketchfusion/blob/main/src/SD_CLIP/model_utils/corr_map_model.py"
    click Fusion3 "https://github.com/tapaskumardutta1/sketchfusion/blob/main/src/SD_CLIP/model_utils/resnet.py"

    %% Click Event for Training Pipeline
    click Train "https://github.com/tapaskumardutta1/sketchfusion/blob/main/src/SD_CLIP/pck_train_combined.py"

    %% Click Events for General Utilities
    click Loss "https://github.com/tapaskumardutta1/sketchfusion/blob/main/src/SD_CLIP/utils/utils_losses.py"
    click CorrUtils "https://github.com/tapaskumardutta1/sketchfusion/blob/main/src/SD_CLIP/utils/utils_correspondence.py"
    click SDUtils "https://github.com/tapaskumardutta1/sketchfusion/blob/main/src/SD_CLIP/utils/utils_SD_CLIP.py"

    %% Click Event for Visual Assets
    click VA "https://github.com/tapaskumardutta1/sketchfusion/tree/main/static"

    %% Styles
    classDef input fill:#cfe2f3,stroke:#333,stroke-width:2px;
    classDef config fill:#f9cb9c,stroke:#333,stroke-width:2px;
    classDef foundation fill:#d9ead3,stroke:#333,stroke-width:2px;
    classDef fusion fill:#ead1dc,stroke:#333,stroke-width:2px;
    classDef training fill:#fff2cc,stroke:#333,stroke-width:2px;
    classDef utilities fill:#d0e0e3,stroke:#333,stroke-width:2px;
    classDef output fill:#d9d2e9,stroke:#333,stroke-width:2px;
    classDef visuals fill:#ead3cb,stroke:#333,stroke-width:2px;
```
