# wangerniuniu/fabricdefectdetection architecture

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

- Interactive diagram: https://gitdiagram.com/wangerniuniu/fabricdefectdetection
- Repository: https://github.com/wangerniuniu/fabricdefectdetection

## Overview

##### Project type and purpose
- This is a research‐oriented deep learning project (“FabricDefectDetection”) that implements a real‐time fabric defect segmentation network in PyTorch.
- Its primary function is loading labeled fabric defect images, passing them through a convolutional segmentation model (defined in model.py), and producing defect masks.

##### File structure
- Top level:
- HKSEG/… : six subfolders (BrokenEnd, Hole, Knots, NettingMultiple, ThickBar, ThinBar), each containing image datasets and any annotation attachments.
- model.py : the core model definition, training and inference scripts (often combined).
- README.md : project overview, prerequisites, model visuals and performance stats.

##### README for additional insights
- Confirms use of Ubuntu + Python3.5 + PyTorch1.0 + CUDA9.0
- Mentions external labeling tool for annotation.

##### Main components
a. Data Component
- Raw image datasets (HKSEG/… folders)
b. Data Pipeline
- ImageReader & Preprocessing (crop, resize, normalization)
- DataLoader (batching, shuffling)
c. Model Component
- Convolutional Neural Network (encoder‐decoder segmentation architecture from image/net.png)
- Intermediate blocks (residual/dense blocks as per image/details.png)
d. Training Loop
- Loss computation (e.g., cross‐entropy, IoU loss)
- Optimizer (SGD/Adam), learning‐rate scheduler
- Backpropagation on GPU (CUDA 9.0)
e. Inference & Postprocessing
- Softmax threshold, morphological cleaning
- Overlay masks on original images
f. Outputs & Evaluation
- Visual results (result1.png, result2.png)
- FLOPs & model‐size metrics (flops.jpg, modelsize.jpg)
g. External Services

##### Relationships and interactions
- Data → Preprocessing → DataLoader → Model → Loss & Optimizer ↺ Model (training)
- For inference: DataLoader → Model → Postprocessing → Result Storage/Visualization
- The GPU runtime (CUDA) underpins Model and Training Loop operations.

##### Architectural patterns & design principles
- Modular pipeline: separation of data ingestion, model definition, and training/inference logic.
- Encoder‐decoder segmented network (common segmentation pattern).
- Hardware abstraction: PyTorch’s CUDA backend abstracts GPU details.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Components
    DataStorage["Data Storage\n(HKSEG/)"]:::data
    ProjectOverview["Project Overview & External\n(README, Labeling Tool)"]:::external

    %% Compute Pipeline
    Preprocessing["Preprocessing Module\n(crop, resize, normalization)"]:::compute
    DataLoader["DataLoader Module\n(batching, shuffling)"]:::compute

    subgraph "GPU Runtime (CUDA 9.0)"
        direction TB
        SegModel["Segmentation Model\n(encoder-decoder & blocks)"]:::compute
        TrainingLoop["Training Loop\n(loss, optimizer,\noptimizer, scheduler,\nbackprop)"]:::compute
    end

    Inference["Inference & Postprocessing\n(softmax, mask overlay)"]:::compute

    %% Outputs
    Outputs["Outputs & Evaluation\n(visual results,\nFLOPs & model-size)"]:::output

    %% External Service
    LabelTool["External Labeling Tool"]:::external

    %% Dataflow Relationships
    DataStorage -->|provides images| Preprocessing
    Preprocessing -->|processed batches| DataLoader
    DataLoader -->|batches| SegModel
    SegModel -->|features| TrainingLoop
    TrainingLoop -->|updated weights| SegModel
    DataLoader -->|batches| Inference
    Inference -->|masks| Outputs

    %% External Links
    ProjectOverview -->|describes| DataStorage
    ProjectOverview -->|links to| LabelTool

    %% Click Events
    click DataStorage "https://github.com/wangerniuniu/fabricdefectdetection/tree/master/HKSEG/"
    click Preprocessing "https://github.com/wangerniuniu/fabricdefectdetection/blob/master/model.py"
    click DataLoader "https://github.com/wangerniuniu/fabricdefectdetection/blob/master/model.py"
    click SegModel "https://github.com/wangerniuniu/fabricdefectdetection/blob/master/model.py"
    click TrainingLoop "https://github.com/wangerniuniu/fabricdefectdetection/blob/master/model.py"
    click Inference "https://github.com/wangerniuniu/fabricdefectdetection/blob/master/model.py"
    click Outputs "https://github.com/wangerniuniu/fabricdefectdetection/tree/master/image/"
    click ProjectOverview "https://github.com/wangerniuniu/fabricdefectdetection/blob/master/README.md"

    %% Styling
    classDef data fill:#e0f7e9,stroke:#1a8734,color:#1a8734
    classDef compute fill:#e1ecf9,stroke:#265a9e,color:#265a9e
    classDef external fill:#fff4e5,stroke:#d48806,color:#d48806
    classDef output fill:#f0f0f0,stroke:#6c6c6c,color:#6c6c6c
    style GPU_Runtime stroke-dasharray: 5 5,stroke:#888888,fill:none
```
