# zhixuhao/unet architecture

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

- Interactive diagram: https://gitdiagram.com/zhixuhao/unet
- Repository: https://github.com/zhixuhao/unet

## Overview

##### Project type and purpose
- This is a research‐oriented deep-learning image segmentation project implementing the U-Net architecture in Keras.
- It ingests a biomedical microscopy dataset (“membrane”) and trains a convolutional network to produce pixel-wise segmentation masks.

##### File structure
Top-level files and folders reveal the main components:
- data/                ← raw and pre-processed images (train, test, labels, augmented)
- data.py              ← Python module for loading and augmenting data
- dataPrepare.ipynb    ← notebook that explores and preprocesses the data, generates augmentations
- model.py             ← U-Net model definition using Keras functional API
- trainUnet.ipynb      ← interactive training notebook
- main.py              ← CLI entry point for running inference on test images
- README.md, LICENSE  ← documentation and licensing

##### Extract key architecture details from README
- Data augmentation via Keras’s ImageDataGenerator
- Model: U-Net with encoder/decoder paths, skip connections, sigmoid output for mask prediction
- Training: binary crossentropy loss, five epochs, using TensorFlow backend
- Inference: main.py applies the trained model to test images and writes segmentation masks

a. Main components:
1. Raw Data Storage (data/membrane)
2. Data Preparation & Augmentation Module (data.py + dataPrepare.ipynb)
3. Model Definition (model.py)
4. Training Engine (trainUnet.ipynb + Keras/TensorFlow)
5. Inference Engine (main.py + Keras/TensorFlow)
6. Output Storage & Visualization (img/, output folder)
7. External Libraries (Keras, TensorFlow, Python)

b. Data flow / interactions:
- Raw images → Data Preparation & Augmentation → Augmented dataset
- Augmented dataset + model definition → Training Engine → Trained model artifacts
- Trained model + test images → Inference Engine → Segmentation masks → Output Storage/Visualization

c. Architectural patterns/design principles:
- Modular separation: I/O & preprocessing (data.py & notebooks), model architecture (model.py), training vs. inference logic (trainUnet.ipynb vs. main.py)
- Reproducibility via notebooks and a single CLI entry point
- Functional API in Keras enforces clear graph of layers (the U-Net)

d. Key technologies/frameworks:
- Python 2.7–3.5
- Keras (>=1.0) on TensorFlow backend
- Jupyter notebooks for interactive exploration and training
- ImageDataGenerator for on-the-fly augmentation

##### Elements
- Clear labels: “Raw Data”, “Augmentor”, “U-Net Model”, “Trainer”, “Inferencer”, “Outputs”
– Rectangles for modules (data, preprocessing, model)
– Hexagons or clouds for external dependencies (Keras, TensorFlow)

## Diagram (Mermaid)

```mermaid
flowchart TD
    classDef storage fill:#f9f,stroke:#333,stroke-width:1px
    classDef process fill:#bfb,stroke:#333,stroke-width:1px
    classDef model fill:#bbf,stroke:#333,stroke-width:1px
    classDef external fill:#fbf,stroke:#333,stroke-width:1px
    classDef doc fill:#ffd,stroke:#333,stroke-width:1px

    subgraph "File System: Raw Data"
        RawData["Raw Data Storage"]:::storage
        TrainVol["train-volume.tif"]:::storage
        TrainLabels["train-labels.tif"]:::storage
        TestVol["test-volume.tif"]:::storage
        RawData --> TrainVol
        RawData --> TrainLabels
        RawData --> TestVol
        AugFolder["train/aug"]:::storage
        RawData --> AugFolder
        Image["image"]:::storage
        Label["label"]:::storage
        AugFolder --> Image
        AugFolder --> Label
    end

    subgraph "Data Preparation & Augmentation"
        DataScript["data.py"]:::process
        DataNotebook["dataPrepare.ipynb"]:::process
        RawData --> DataScript
        RawData --> DataNotebook
        DataScript --> AugData["Augmented Dataset"]:::storage
        DataNotebook --> AugData
    end

    subgraph "Model Definition & Training"
        ModelDef["model.py"]:::model
        Trainer["trainUnet.ipynb"]:::process
        AugData --> Trainer
        ModelDef --> Trainer
        Trainer --> TrainedModel["Trained Model Weights"]:::storage
    end

    subgraph "Inference"
        Inferencer["main.py"]:::process
        TestVol --> Inferencer
        TrainedModel --> Inferencer
        Inferencer --> Masks["Predicted Masks"]:::storage
    end

    Masks --> Output["Output Storage (img/)"]:::storage

    Keras["Keras"]:::external
    TensorFlow["TensorFlow"]:::external
    Keras --> Trainer
    TensorFlow --> Trainer
    Keras --> Inferencer
    TensorFlow --> Inferencer

    README["README.md"]:::doc
    License["LICENSE"]:::doc

    click RawData "https://github.com/zhixuhao/unet/tree/master/data/membrane"
    click TrainVol "https://github.com/zhixuhao/unet/blob/master/data/membrane/train-volume.tif"
    click TrainLabels "https://github.com/zhixuhao/unet/blob/master/data/membrane/train-labels.tif"
    click TestVol "https://github.com/zhixuhao/unet/blob/master/data/membrane/test-volume.tif"
    click AugFolder "https://github.com/zhixuhao/unet/tree/master/data/membrane/train/aug"
    click Image "https://github.com/zhixuhao/unet/tree/master/data/membrane/train/image"
    click Label "https://github.com/zhixuhao/unet/tree/master/data/membrane/train/label"
    click DataScript "https://github.com/zhixuhao/unet/blob/master/data.py"
    click DataNotebook "https://github.com/zhixuhao/unet/blob/master/dataPrepare.ipynb"
    click ModelDef "https://github.com/zhixuhao/unet/blob/master/model.py"
    click Trainer "https://github.com/zhixuhao/unet/blob/master/trainUnet.ipynb"
    click Inferencer "https://github.com/zhixuhao/unet/blob/master/main.py"
    click Output "https://github.com/zhixuhao/unet/tree/master/img/"
    click README "https://github.com/zhixuhao/unet/blob/master/README.md"
    click License "https://github.com/zhixuhao/unet/tree/master/LICENSE"
```
