# cuihaoleo/cnn_watermark architecture

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

- Interactive diagram: https://gitdiagram.com/cuihaoleo/cnn_watermark
- Repository: https://github.com/cuihaoleo/cnn_watermark

## Overview

##### Project type and purpose
- This is an open-source research/tool repository that implements a CNN-based watermarking scheme in TensorFlow Keras, using the CIFAR-10 dataset.
- Purpose: train a watermark-aware CNN model (cnn_watermark.py), then evaluate watermark embedding, robustness (add_noise.py), and extraction (extract.py).

##### File structure
- Top level
- cnn_watermark.py – training pipeline that loads CIFAR-10, builds and trains the CNN, and serializes the model.
- eval/ – evaluation scripts that operate independently:
– embed.py: embeds a watermark into images using the trained model.
– add_noise.py: simulates attacks by adding noise to watermarked images.
– extract.py: extracts the watermark from noisy images.
- No frontend/backend split; this is a standalone Python workflow. No deployment scripts.

##### README for additional insights
- Confirms usage of TensorFlow Keras and CIFAR-10.
- Clear separation between “training” (cnn_watermark.py) and “evaluation” (eval/).

##### Detailed breakdown—don’t overthink
- Break the project into the six components above.
- Storage artifacts (dataset, model file, image files).
- Data dependencies: which files or outputs feed into which module.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Data Loading and Training Lifecycle
    CIFAR["CIFAR-10 Dataset"]:::data
    Training["Training Module\n(cnn_watermark.py)"]:::life
    Model["Model Artifact\n(.h5/.ckpt)"]:::data

    %% Evaluation Pipeline
    subgraph "Evaluation Pipeline"
      Embedding["Embedding Module\n(eval/embed.py)"]:::eval
      Watermarked["Watermarked Images"]:::data
      Noise["Noise-Attack Module\n(eval/add_noise.py)"]:::eval
      Noisy["Noisy Images"]:::data
      Extraction["Extraction Module\n(eval/extract.py)"]:::eval
      Recovered["Recovered Watermarks"]:::data
      Evaluation["Evaluation & Reporting\n(metrics/plots)"]:::eval
    end

    %% Data Flows
    CIFAR -->|"loads data"| Training
    Training -->|"saves model"| Model
    Model -->|"loaded by"| Embedding
    CIFAR -->|"raw images"| Embedding
    Embedding -->|"outputs .png"| Watermarked
    Watermarked -->|"inputs to"| Noise
    Noise -->|"outputs .png"| Noisy
    Model -->|"loaded by"| Extraction
    Noisy -->|"inputs to"| Extraction
    Extraction -->|"extracts watermark"| Recovered
    Recovered -->|"generates metrics"| Evaluation

    %% Click Events
    click Training "https://github.com/cuihaoleo/cnn_watermark/blob/master/cnn_watermark.py"
    click Embedding "https://github.com/cuihaoleo/cnn_watermark/blob/master/eval/embed.py"
    click Noise "https://github.com/cuihaoleo/cnn_watermark/blob/master/eval/add_noise.py"
    click Extraction "https://github.com/cuihaoleo/cnn_watermark/blob/master/eval/extract.py"

    %% Styles
    classDef data fill:#ffeb99,stroke:#333,stroke-width:1px
    classDef life fill:#f9ccea,stroke:#333,stroke-width:1px
    classDef eval fill:#b2f7ef,stroke:#333,stroke-width:1px
```
