# drlxj/camdiff architecture

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

- Interactive diagram: https://gitdiagram.com/drlxj/camdiff
- Repository: https://github.com/drlxj/camdiff

## Overview

##### Project Type and Purpose
- This is an open-source image‐augmentation framework that uses a latent diffusion model to overlay salient objects onto camouflaged scenes, validated by a CLIP zero-shot classifier.
- It consumes existing COD datasets (images + masks), augments them, and outputs new synthesized images. Ancillary scripts handle classification and paper analyses.

##### Main Components
a. Data Layer
- COD Datasets (Imgs + GT masks)
- Output folders (resulting “new”, “new1+1”, “new3”)
b. Preprocessing
- Script: inpainting_diff.py (or inpaint.sh) reads images & masks, resizes/crops, prepares conditioning masks.
c. Core Inpainting Pipeline
- Latent Diffusion Model (Stable Diffusion inpainting, via HuggingFace diffusers)
- Conditioning on mask and text prompt
d. CLIP Zero-Shot Classifier
- Script: clip_classification.py verifies that the synthesized object aligns with the text prompt
- Rejects or flags misaligned inpainted images
e. Postprocessing & Dataset Packaging
- Accepted images into “new*” folders mimicking COD training/test structure
f. Evaluation / Paper Generation
- Script: paper.py for quantitative/qualitative plots
g. Environment & Dependencies
- Conda environment (Python 3.10, PyTorch, diffusers, transformers, CLIP)
- External models (HuggingFace latent-diffusion weights, OpenAI CLIP repo)

##### Relationships & Data Flow
[COD Dataset] → [Preprocessor] → [Diffusion Inpainting Engine] → [CLIP Classifier] → [Postprocessor] → [Augmented Dataset]
- Branch off to [Evaluation Module (paper.py)] feeding from both original and augmented datasets.

##### Architectural Patterns
- Linear data-processing pipeline with “filter” stage (CLIP).
- Modular scripts each handling a single responsibility (separation of concerns).
- Pluggable external services (diffusers model hub, CLIP repo).

- Components listed above with clear labels.
- Compute (rectangles)
- External (clouds)
- Pipeline is linear but annotate parallel evaluations or feedback loops.
- Do not overcomplicate—clearly separate into:
1. Input
2. Processing stages (3 modules)
3. Output
4. Evaluation

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Stores
    OriginalDataset["Original COD Datasets<br>(Imgs + Masks)"]:::data
    AugmentedDataset["Augmented COD Dataset"]:::data

    %% External Dependencies
    HuggingFace["HuggingFace Model Hub"]:::external
    CLIPRepo["OpenAI CLIP Repo"]:::external

    %% Environment Boundary
    subgraph "Conda env: camdiff<br>(PyTorch, diffusers, transformers, CLIP)"
        direction TB
        Preprocessor["Preprocessor<br>(inpainting_diff.py)"]:::proc
        ShellScript["Shell Script<br>(inpaint.sh)"]:::glue
        Diffusion["Diffusion Engine<br>(inpainting_diff.py)"]:::proc
        CLIP["CLIP Classifier<br>(clip_classification.py)"]:::proc
        Postprocessor["Postprocessor<br>(inpainting_diff.py)"]:::proc
        Evaluation["Evaluation Module<br>(paper.py)"]:::proc
    end

    %% Documentation
    README["README.md"]:::glue

    %% Data Flow
    OriginalDataset -->|"images + masks"| Preprocessor
    Preprocessor -->|"prepared masks + resized image"| ShellScript
    ShellScript -->|"latent tensor + mask"| Diffusion
    Diffusion -->|"synthesized image"| CLIP
    CLIP -->|"verified images"| Postprocessor
    Postprocessor -->|"augmented .jpg + masks"| AugmentedDataset

    OriginalDataset -->|"original dataset"| Evaluation
    AugmentedDataset -->|"augmented dataset"| Evaluation

    %% External Links
    HuggingFace -.-> Diffusion
    CLIPRepo -.-> CLIP

    %% Documentation Link
    README -.->|"setup & instructions"| Preprocessor

    %% Click Events
    click OriginalDataset "https://github.com/drlxj/camdiff/tree/main/Imgs/"
    click Preprocessor "https://github.com/drlxj/camdiff/blob/main/inpainting_diff.py"
    click ShellScript "https://github.com/drlxj/camdiff/blob/main/inpaint.sh"
    click Diffusion "https://github.com/drlxj/camdiff/blob/main/inpainting_diff.py"
    click CLIP "https://github.com/drlxj/camdiff/blob/main/clip_classification.py"
    click Postprocessor "https://github.com/drlxj/camdiff/blob/main/inpainting_diff.py"
    click Evaluation "https://github.com/drlxj/camdiff/blob/main/paper.py"
    click README "https://github.com/drlxj/camdiff/blob/main/README.md"

    %% Styling
    classDef data fill:#E3F2FD,stroke:#0D47A1,stroke-width:2px
    classDef proc fill:#E8F5E9,stroke:#1B5E20,stroke-width:2px
    classDef glue fill:#F5F5F5,stroke:#9E9E9E,stroke-width:2px,stroke-dasharray:5 5
    classDef external fill:#FFF3E0,stroke:#EF6C00,stroke-width:2px
```
