# yannasyr/landcover architecture

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

- Interactive diagram: https://gitdiagram.com/yannasyr/landcover
- Repository: https://github.com/yannasyr/landcover

## Overview

##### Project type and purpose
- This is a machine-learning pipeline for land-cover segmentation from satellite images, built to train, evaluate, and submit predictions for the ENS Challenge Data 2021.
- It comprises exploratory notebooks, a training codebase, and scripts to generate the CSV submission.

##### File structure
Top-level:
- archives/ – Jupyter notebooks and exploratory scripts used for early data visualization and proof-of-concept.
- csv_output/ – Scripts that load a trained model, run inference on test images, and write the challenge-format CSV.
- training/ – Core production code: data loading, preprocessing, model definitions, training loop, evaluation, and utilities.
- requirements.txt – Python dependencies.

Inside training/:
- LandCoverData.py & Landscapedata.py – custom Dataset implementations for train/test.
- normalisation.py & utils.py – preprocessing and helper functions.
- models.py – network architectures (e.g., SegFormer or U-Net variants).
- lossesSegFormerRGB.txt – loss function notes.
- train.py & main.py & arg_parser.py – CLI entry points to kick off training with configurable hyperparameters.
- metrics.py – evaluation metrics (IoU, accuracy).

##### Insights from the README
- The workflow expects a “dataset_UNZIPPED” folder with train/images, train/masks, and test/images.
- You install dependencies, then run the training module to produce a model checkpoint.
- The csv_output scripts convert model outputs on the test set into the submission CSV.

a. Main components:
1. Data Storage
- Raw GeoTIFF files (train images, train masks, test images)
2. Experimentation/Exploration
- Jupyter notebooks under archives/ for visual inspection and prototyping
3. Preprocessing & Data Loader
- normalisation.py, augmentation routines, LandCoverData.py / Landscapedata.py
4. Model Architectures
- models.py defines one or more segmentation models
5. Training Engine
- train.py, main.py with argument parsing, orchestrating epochs, checkpointing
6. Evaluation
- metrics.py computes IoU, accuracy on validation set
7. Inference & Submission
- csv_output scripts load checkpoints, run inference on test images, assemble CSV

b. Relationships and interactions
- Training Engine → Model Architectures (models are instantiated)
- Training Engine → Evaluation → Feedback to Training Engine (early stopping, logging)
- Trained Model Checkpoints → Inference & Submission
- Archives notebooks connect to Data Storage for ad-hoc analysis but do not feed into production pipeline.

c. Architectural patterns and design principles
- Layered / pipeline pattern: clear stages (Ingest → Preprocess → Train → Evaluate → Export)
- Separation of concerns: data handling, model definition, training logic, evaluation, submission are in separate modules
- CLI-driven reproducibility: arg_parser.py / main.py let you configure experiments from the command line

d. Key technologies
- Python 3.x
- Deep learning framework (e.g., PyTorch or TensorFlow; as listed in requirements.txt)
- NumPy, GDAL or rasterio for GeoTIFF I/O
- Pandas for CSV output
- Jupyter for notebooks

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Data Storage and Configuration
    DS[(dataset_UNZIPPED/)]:::data
    Requirements["requirements.txt"]:::config

    %% Exploration Branch
    subgraph "Exploration (archives/)"
        ExpNB["Notebooks"]:::expl
        ExpAug["augmentation.py"]:::expl
        ExpModelProto["models.py"]:::expl
    end

    %% Preprocessing & Data Loader
    subgraph "Preprocessing & Data Loader"
        Norm["normalisation.py"]:::io
        Utils["utils.py"]:::io
        TrainLoader["LandCoverData.py"]:::io
        CSVLoaderAlt["Landscapedata.py"]:::io
        CSVLoaderTrain["Landscapedata.py"]:::io
    end

    %% Model Definitions
    subgraph "Model Architectures"
        ModelTrain["models.py"]:::model
        ModelInf["models.py"]:::model
    end

    %% Training Engine
    subgraph "Training Engine"
        ArgParser["arg_parser.py"]:::config
        MainEntrypoint["main.py"]:::config
        TrainLoop["train.py"]:::config
    end

    %% Evaluation Module
    subgraph "Evaluation"
        Metrics["metrics.py"]:::eval
    end

    %% Inference & CSV Export
    subgraph "Inference & CSV Export"
        InfRunner["train.py"]:::eval
        EvalScript["yann_eval.py"]:::eval
    end

    %% Data Flow and Dependencies
    DS --> Norm
    DS --> ExpNB
    DS --> ExpAug
    DS --> ExpModelProto

    Norm --> Utils
    Utils --> TrainLoader
    TrainLoader --> TrainLoop
    CSVLoaderAlt --> InfRunner
    DS --> CSVLoaderTrain

    ModelTrain --> TrainLoop
    ArgParser --> TrainLoop
    MainEntrypoint --> TrainLoop

    TrainLoop --> Metrics
    Metrics --> TrainLoop

    TrainLoop --> InfRunner
    CSVLoaderTrain --> InfRunner
    ModelInf --> InfRunner
    InfRunner --> EvalScript

    Requirements --> ExpNB
    Requirements --> Norm
    Requirements --> ModelTrain
    Requirements --> InfRunner

    %% Click Events
    click DS "https://github.com/yannasyr/landcover/tree/main/dataset_UNZIPPED/"
    click ExpNB "https://github.com/yannasyr/landcover/tree/main/archives/Notebooks/"
    click ExpAug "https://github.com/yannasyr/landcover/blob/main/archives/augmentation.py"
    click ExpModelProto "https://github.com/yannasyr/landcover/blob/main/archives/Notebooks/models.py"
    click Norm "https://github.com/yannasyr/landcover/blob/main/training/normalisation.py"
    click Utils "https://github.com/yannasyr/landcover/blob/main/training/utils.py"
    click TrainLoader "https://github.com/yannasyr/landcover/blob/main/training/LandCoverData.py"
    click CSVLoaderAlt "https://github.com/yannasyr/landcover/blob/main/training/Landscapedata.py"
    click CSVLoaderTrain "https://github.com/yannasyr/landcover/blob/main/csv_output/Landscapedata.py"
    click ModelTrain "https://github.com/yannasyr/landcover/blob/main/training/models.py"
    click ModelInf "https://github.com/yannasyr/landcover/blob/main/csv_output/models.py"
    click ArgParser "https://github.com/yannasyr/landcover/blob/main/training/arg_parser.py"
    click MainEntrypoint "https://github.com/yannasyr/landcover/blob/main/training/main.py"
    click TrainLoop "https://github.com/yannasyr/landcover/blob/main/training/train.py"
    click Metrics "https://github.com/yannasyr/landcover/blob/main/training/metrics.py"
    click InfRunner "https://github.com/yannasyr/landcover/blob/main/csv_output/train.py"
    click EvalScript "https://github.com/yannasyr/landcover/blob/main/csv_output/yann_eval.py"
    click Requirements "https://github.com/yannasyr/landcover/blob/main/requirements.txt"

    %% Styles
    classDef data fill:#cfe2f3,stroke:#0366d6;
    classDef io fill:#cfe2f3,stroke:#0366d6;
    classDef model fill:#d9ead3,stroke:#38761d;
    classDef config fill:#e7e6af,stroke:#bf9000;
    classDef eval fill:#fce5cd,stroke:#b45f06;
    classDef expl fill:#d9d2e9,stroke:#674ea7;
```
