# rmpku/cin architecture

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

- Interactive diagram: https://gitdiagram.com/rmpku/cin
- Repository: https://github.com/rmpku/cin

## Overview

##### Project type and purpose
- This is a research‐oriented deep‐learning codebase (“CIN”): it implements an invertible neural network combined with non-invertible modules to perform blind watermarking or robust image restoration under noise.
- The README references datasets (COCO2017, DIV2K), a noise pool, pre-trained models, and training details.

##### File structure
- Top level:
· codes/                ← all Python code
· pth/                  ← pretrained model weights
· README.md, .gitignore
- Under codes/:
· main.py              ← entry point that parses options, sets up data, runs train/test
· models/              ← model definition package
– CIN.py, NSM_module.py, DEM.py, FSM.py, IM.py, Network.py, Noise_pool.py
– modules/           ← building blocks: Conv1x1, DenseBlock, the invertible architecture, noise‐injection options, loss functions
· options/             ← configuration loader & YAML file (opt.yml)
· utils/               ← checkpointing, general utilities, YAML parsing

##### README for additional insights
- Architecture overview screenshots under “Framework”, “Visualization”, “invertibleNet”
- Describes noise pool, training details, environment dependencies

##### Elements
- Blue = configuration & I/O
- Green = data processing
- Orange = model internals (invertible vs non-invertible blocks)
- Gray = utilities (checkpoint, logging)

##### Detailed capture of essential architectural elements
- Do not simply lump everything into one block; separate:
· opt.yml reader
· dataset ingestion
· noise‐pool (list the noise options submodules)
· invertible architecture (InvArch, InvDownscaling)
· non-invertible branch (NSM_module, DEM, FSM, IM)
· loss function calculations
· optimizer / training loop
· checkpoint save/load

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Configuration Subsystem"
        A1["Options Loader"]:::blue
        A2["YAML Parser"]:::blue
        A3["opt.yml"]:::blue
    end

    subgraph "Data Ingestion & Preprocessing"
        B1["DataLoader"]:::green
        B2["Noise Pool"]:::green
        B3["Noise Options"]:::green
    end

    subgraph "Model Architecture"
        subgraph "Invertible Subnetwork"
            C1["CIN"]:::orange
            C2["InvArch"]:::orange
            C3["InvDownscaling"]:::orange
        end
        subgraph "Non-Invertible Subnetwork"
            C4["NSM Module"]:::orange
            C5["DEM"]:::orange
            C6["FSM"]:::orange
            C7["IM"]:::orange
        end
        C8["Network Wrapper"]:::orange
        subgraph "Common Blocks & Loss"
            C9["conv_bn_relu"]:::orange
            C10["Conv1x1"]:::orange
            C11["DenseBlock"]:::orange
            C12["Loss Functions"]:::orange
        end
    end

    subgraph "Training & Evaluation Orchestrator"
        D1["main.py"]:::blue
    end

    subgraph "Utilities"
        E1["Checkpoint Utils"]:::gray
        E2["General Utils"]:::gray
    end

    subgraph "External Resources"
        F1["pth/"]:::gray
        F2["download.txt"]:::gray
    end

    D1 -->|"load config"| A1
    A1 -->|"parse config"| A2
    A2 -->|"reads file"| A3

    D1 -->|"setup DataLoader"| B1
    B1 -->|"feeds images"| B2
    B2 -->|"loads options"| B3
    B2 -->|"outputs noised images"| C1

    C1 --> C2
    C2 --> C3
    C3 --> C8

    C8 --> C4
    C4 --> C5
    C5 --> C6
    C6 --> C7
    C7 --> C8

    C8 --> C12
    C9 --> C12
    C10 --> C12
    C11 --> C12
    C12 -->|"loss value"| D1

    D1 -->|"calls checkpoint"| E1
    E1 -->|"saves weights"| F1
    F1 --> F2
    D1 -->|"loads pretrained"| F1

    click A1 "https://github.com/rmpku/cin/blob/main/codes/options/__init__.py"
    click A2 "https://github.com/rmpku/cin/blob/main/codes/utils/yml.py"
    click A3 "https://github.com/rmpku/cin/blob/main/codes/options/opt.yml"
    click B2 "https://github.com/rmpku/cin/blob/main/codes/models/Noise_pool.py"
    click B3 "https://github.com/rmpku/cin/tree/main/codes/models/modules/Noise_option/"
    click C1 "https://github.com/rmpku/cin/blob/main/codes/models/CIN.py"
    click C2 "https://github.com/rmpku/cin/blob/main/codes/models/modules/InvArch.py"
    click C3 "https://github.com/rmpku/cin/blob/main/codes/models/modules/InvDownscaling.py"
    click C4 "https://github.com/rmpku/cin/blob/main/codes/models/NSM_module.py"
    click C5 "https://github.com/rmpku/cin/blob/main/codes/models/DEM.py"
    click C6 "https://github.com/rmpku/cin/blob/main/codes/models/FSM.py"
    click C7 "https://github.com/rmpku/cin/blob/main/codes/models/IM.py"
    click C8 "https://github.com/rmpku/cin/blob/main/codes/models/Network.py"
    click C9 "https://github.com/rmpku/cin/blob/main/codes/models/modules/conv_bn_relu.py"
    click C10 "https://github.com/rmpku/cin/blob/main/codes/models/modules/Conv1x1.py"
    click C11 "https://github.com/rmpku/cin/blob/main/codes/models/modules/DenseBlock.py"
    click C12 "https://github.com/rmpku/cin/blob/main/codes/models/modules/loss.py"
    click D1 "https://github.com/rmpku/cin/blob/main/codes/main.py"
    click E1 "https://github.com/rmpku/cin/blob/main/codes/utils/checkpoint.py"
    click E2 "https://github.com/rmpku/cin/blob/main/codes/utils/utils.py"
    click F1 "https://github.com/rmpku/cin/tree/main/pth/"
    click F2 "https://github.com/rmpku/cin/blob/main/pth/download.txt"

    classDef blue fill:#D0E6FF,stroke:#0366D6,color:#0366D6
    classDef green fill:#E6FFF2,stroke:#028A0F,color:#028A0F
    classDef orange fill:#FFEFD5,stroke:#FF8C00,color:#FF8C00
    classDef gray fill:#F5F5F5,stroke:#909090,color:#909090
```
