# tejasri19/stressnet architecture

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

- Interactive diagram: https://gitdiagram.com/tejasri19/stressnet
- Repository: https://github.com/tejasri19/stressnet

## Overview

##### Project type and purpose
- This is a machine-learning research pipeline for water-stress classification in maize.
- It consists of two main stages: data preparation/segmentation (R script) and model training/evaluation (Python/PyTorch).

##### File structure
- Top level:
- Data_Preparation/Plot_Segmentation.R & Readme.md
- README.md (project overview)
- StressNet/ (Jupyter notebook, model scripts, model_graph.pdf)
- The directory names imply:
- A standalone R-based segmentation step
- A PyTorch-based modeling step with multiple versions of model code (model.py through model10.py) and a main_code.ipynb notebook.

##### README for additional insights
- Dependencies: Python 3.8.17, PyTorch 1.8.0, TorchVision 0.9.0, Anaconda.
- The core architecture is a deformable-attention network combining spatial, spectral and temporal branches.

##### Main components
a. Data sources (multispectral images, time-series data per plot)
b. Data preparation/segmentation
- R script: Plot_Segmentation.R
- Output: segmented plot masks or cropped images
c. Data ingestion & preprocessing
- Python data loader (in main_code.ipynb)
- Steps: channel‐wise extraction, normalization, batching
d. Model architecture (StressNet)
- Spatial branch
- Spectral branch
- Temporal branch
- Deformable attention fusion layer
e. Training & evaluation
- Training loop in PyTorch
- Loss computation, backprop, metrics
f. Outputs
- Water stress classification labels
- Model checkpoints, performance plots (as in model_graph.pdf)

##### Architectural patterns and design principles
- Pipeline pattern (clear stage separation)
- Modularization (R for segmentation, Python for modeling)
- Reproducibility (conda environment, Jupyter notebook for experiments)
- Versioning of model code for incremental experiments (model.py → model10.py)

##### Key technologies/frameworks
- R (Plot_Segmentation.R)
- Python 3.8.17, Anaconda
- PyTorch 1.8.0, TorchVision 0.9.0
- Jupyter Notebook (main_code.ipynb)

##### Detailed capture of essential elements
- Hyperparameters or configs if desired (e.g., batch size, learning rate).
- External dependencies (PyTorch, TorchVision) as annotations near the model component.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Data Preparation Layer
    subgraph "Data Preparation" 
        direction TB
        RawImages["Raw Multispectral & Time-series Images"]:::dataStore
        RSegmentation["R: Plot Segmentation"]:::process
        SegmentedImages["Segmented Plot Masks"]:::dataStore
        ReadmeDP["Data Prep Readme"]:::doc
    end

    %% Data Ingestion & Preprocessing Layer
    subgraph "Data Ingestion & Preprocessing"
        direction TB
        DataLoader["Python: Data Loader & Preprocessing"]:::process
    end

    %% Model Architecture Layer
    subgraph "StressNet Model Architecture"
        direction TB
        Spatial["Spatial Branch"]:::model
        Spectral["Spectral Branch"]:::model
        Temporal["Temporal Branch"]:::model
        DeformableAttention["Deformable Attention Fusion"]:::model
        ModelDiagram["Model Architecture Diagram"]:::doc
    end

    %% Experimental Variants
    subgraph "Experimental Model Variants"
        direction TB
        Model2["model2.py"]:::model
        Model3["model3.py"]:::model
        Model4["model4.py"]:::model
        Model5["model5.py"]:::model
        Model6["model6.py"]:::model
        Model7["model7.py"]:::model
        Model8["model8.py"]:::model
        Model9["model9.py"]:::model
        Model10["model10.py"]:::model
    end

    %% Training & Evaluation Layer
    subgraph "Training & Evaluation"
        direction TB
        TrainingLoop["PyTorch Training Loop"]:::process
        ModelWeights["Model Checkpoints"]:::dataStore
        ClassificationLabels["Classification Outputs"]:::output
        EvaluationMetrics["Evaluation Metrics & Plots"]:::output
        Overview["Project Overview Readme"]:::doc
    end

    %% Connections
    RawImages -->|"multispectral images"| RSegmentation
    RSegmentation -->|"segmented masks"| SegmentedImages
    SegmentedImages -->|"batches of tensors"| DataLoader
    DataLoader -->|"input tensors"| Spatial
    DataLoader -->|"input tensors"| Spectral
    DataLoader -->|"input tensors"| Temporal
    Spatial --> DeformableAttention
    Spectral --> DeformableAttention
    Temporal --> DeformableAttention
    DeformableAttention -->|"fused features"| TrainingLoop
    TrainingLoop -->|"updates"| ModelWeights
    ModelWeights -->|"loaded weights"| TrainingLoop
    TrainingLoop -->|"predictions"| ClassificationLabels
    TrainingLoop -->|"metrics data"| EvaluationMetrics
    Overview --> RawImages

    %% Click Events
    click RSegmentation "https://github.com/tejasri19/stressnet/blob/main/Data_Preparation/Plot_Segmentation.R"
    click ReadmeDP "https://github.com/tejasri19/stressnet/blob/main/Data_Preparation/Readme.md"
    click Overview "https://github.com/tejasri19/stressnet/blob/main/README.md"
    click DataLoader "https://github.com/tejasri19/stressnet/blob/main/StressNet/main_code.ipynb"
    click ModelDiagram "https://github.com/tejasri19/stressnet/blob/main/StressNet/model_graph.pdf"
    click Spatial "https://github.com/tejasri19/stressnet/blob/main/StressNet/model.py"
    click Spectral "https://github.com/tejasri19/stressnet/blob/main/StressNet/model.py"
    click Temporal "https://github.com/tejasri19/stressnet/blob/main/StressNet/model.py"
    click DeformableAttention "https://github.com/tejasri19/stressnet/blob/main/StressNet/model.py"
    click Model2 "https://github.com/tejasri19/stressnet/blob/main/StressNet/model2.py"
    click Model3 "https://github.com/tejasri19/stressnet/blob/main/StressNet/model3.py"
    click Model4 "https://github.com/tejasri19/stressnet/blob/main/StressNet/model4.py"
    click Model5 "https://github.com/tejasri19/stressnet/blob/main/StressNet/model5.py"
    click Model6 "https://github.com/tejasri19/stressnet/blob/main/StressNet/model6.py"
    click Model7 "https://github.com/tejasri19/stressnet/blob/main/StressNet/model7.py"
    click Model8 "https://github.com/tejasri19/stressnet/blob/main/StressNet/model8.py"
    click Model9 "https://github.com/tejasri19/stressnet/blob/main/StressNet/model9.py"
    click Model10 "https://github.com/tejasri19/stressnet/blob/main/StressNet/model10.py"

    %% Styles
    classDef dataStore fill:#cce5ff,stroke:#004085,color:#004085;
    classDef process fill:#d4edda,stroke:#155724,color:#155724;
    classDef model fill:#ffe5b4,stroke:#e69500,color:#e69500;
    classDef output fill:#e2d7f0,stroke:#5f259f,color:#5f259f;
    classDef doc fill:#f8f9fa,stroke:#6c757d,color:#6c757d,stroke-dasharray: 5 5;
```
