# doguilmak/classify-trees-from-satellite-imagery architecture

> Architecture diagram of the GitHub repository doguilmak/classify-trees-from-satellite-imagery, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/doguilmak/classify-trees-from-satellite-imagery
- Repository: https://github.com/doguilmak/classify-trees-from-satellite-imagery

## Overview

Based on our analysis of both the file tree and the README, this project is a computer vision classification system that uses satellite imagery to detect whether images contain trees or not. It’s not a full-blown web application but a data science/machine learning project, where different Jupyter notebooks (and their corresponding Python script versions) guide you through data preparation, visualization, model training (using pre-trained ResNet-50 and VGG16 architectures), and finally, model analysis with a Class Activation Map (CAM) approach. Keep in mind that the project produces intermediate outputs (CSV files with predictions and other dataset splits) and saves the best performing model (best_model.h5).

##### Main Components
- Data Source: Represent the raw satellite imagery data (organized as images of size 64x64 within “tree” and “notree” classes) together with the dataset splits (train, test, and validation CSV files located in the “cam_model_csv_files” directory).
- Data Preparation / Preprocessing: Include components for data preparation and visualization as performed in notebooks “1_0_data_preparation.ipynb” and “1_0_load_and_display_data.ipynb” (and their corresponding py scripts in notebooks_as_py).
- Model Training Components:
- ResNet-50 based training module implemented in “2_0_pretrained_models_resnet50.ipynb.”
- VGG16 based training module in “3_0_pretrained_models_vgg16.ipynb.”
- CAM-based model training and analysis module in “4_0_model_with_cam.ipynb.”
- Model Artifacts:
- The finalized best model saved as “best_model.h5.”
- Output predictions (CSV files) and other logs generated from the CAM experiments.
- Auxiliary/Supporting Files: The notebooks_as_py directory serves as an alternate code representation for each notebook and can be noted as aiding reproducibility or as part of a versioning practice.

##### Relationships and Interactions
- Data flows from the input satellite imagery through a preprocessing pipeline. Start with the preparation and loading steps to ensure the data are well-organized and visualized.
- After data preparation, the processed data is fed into the training modules for both the ResNet-50 and VGG16 approaches.
- These models are trained and evaluated, with performance metrics guiding which model (or model configuration) is chosen as the best. The CAM-based approach then refines the analysis by providing visual explanations via Class Activation Maps.
- The best performing model is then saved (best_model.h5) and the test results are recorded in the CSV prediction files.

##### Architectural Patterns and Design Principles
- The project leverages transfer learning (using pre-trained ResNet-50 and VGG16 models) which implies a modular training approach: one module loads the pre-trained network, applies necessary modifications (if any), and then fine-tunes on the tree dataset.
- The sequential organization of notebooks corresponds to a processing pipeline: first, data is visualized and preprocessed; after that, multiple models are trained and compared.
- Reproducibility and clarity by noting the existence of both Notebook and Python script versions—this represents an emphasis on modularity and code reuse.

##### Relevant Technologies to Highlight
- Deep Learning frameworks (likely Keras/TensorFlow—since the README mentions the Keras Sequential model).
- Pre-trained model architectures from ResNet-50 and VGG16.
- Data handling tools (the use of Jupyter Notebooks for interactive exploration and analysis).

##### Following points to the principal software engineer
- Detail every component and label it with its respective role and relevant file names.
- Annotations about key parameters (like image resolution, number of classes, architectural highlights of ResNet-50 and VGG16) where they add clarity.

## Diagram (Mermaid)

```mermaid
flowchart TD
    DS["Raw Satellite Imagery Data (64x64, tree & notree)"]:::data
    DS --> DP1["1_0_data_preparation.ipynb"]:::prep
    DP1 --> DP2["1_0_load_and_display_data.ipynb"]:::prep
    DP1 --> DP1_py["1_0_data_preparation.py"]:::aux
    DP2 --> DP2_py["1_0_load_and_display_data.py"]:::aux

    DP2 --> R["ResNet-50 Training (2_0_pretrained_models_resnet50.ipynb)"]:::train
    DP2 --> V["VGG16 Training (3_0_pretrained_models_vgg16.ipynb)"]:::train
    DP2 --> C["CAM Analysis (4_0_model_with_cam.ipynb)"]:::train

    R --> R_py["2_0_pretrained_models_resnet50.py"]:::aux
    V --> V_py["3_0_pretrained_models_vgg16.py"]:::aux
    C --> C_py["4_0_model_with_cam.py"]:::aux

    subgraph "Model Evaluation & Persistence"
        ME_A["Best Model Artifact (best_model.h5)"]:::eval
        ME_L["Predictions & Logs (cam_model_csv_files)"]:::eval
    end

    R -->|"to artifacts"| ME_A
    R -->|"to outputs"| ME_L
    V -->|"to artifacts"| ME_A
    V -->|"to outputs"| ME_L
    C -->|"to artifacts"| ME_A
    C -->|"to outputs"| ME_L

click DS "https://github.com/doguilmak/classify-trees-from-satellite-imagery/tree/main/cam_model_csv_files"
click DP1 "https://github.com/doguilmak/classify-trees-from-satellite-imagery/blob/main/1_0_data_preparation.ipynb"
click DP2 "https://github.com/doguilmak/classify-trees-from-satellite-imagery/blob/main/1_0_load_and_display_data.ipynb"
click DP1_py "https://github.com/doguilmak/classify-trees-from-satellite-imagery/blob/main/notebooks_as_py/1_0_data_preparation.py"
click DP2_py "https://github.com/doguilmak/classify-trees-from-satellite-imagery/blob/main/notebooks_as_py/1_0_load_and_display_data.py"
click R "https://github.com/doguilmak/classify-trees-from-satellite-imagery/blob/main/2_0_pretrained_models_resnet50.ipynb"
click R_py "https://github.com/doguilmak/classify-trees-from-satellite-imagery/blob/main/notebooks_as_py/2_0_pretrained_models_resnet50.py"
click V "https://github.com/doguilmak/classify-trees-from-satellite-imagery/blob/main/3_0_pretrained_models_vgg16.ipynb"
click V_py "https://github.com/doguilmak/classify-trees-from-satellite-imagery/blob/main/notebooks_as_py/3_0_pretrained_models_vgg16.py"
click C "https://github.com/doguilmak/classify-trees-from-satellite-imagery/blob/main/4_0_model_with_cam.ipynb"
click C_py "https://github.com/doguilmak/classify-trees-from-satellite-imagery/blob/main/notebooks_as_py/4_0_model_with_cam.py"
click ME_A "https://github.com/doguilmak/classify-trees-from-satellite-imagery/blob/main/best_model.h5"
click ME_L "https://github.com/doguilmak/classify-trees-from-satellite-imagery/tree/main/cam_model_csv_files"

classDef data fill:#C7E9C0,stroke:#2E7D32,stroke-width:2px;
classDef prep fill:#AED6F1,stroke:#1565C0,stroke-width:2px;
classDef train fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
classDef eval fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
classDef aux fill:#D7BDE2,stroke:#8E44AD,stroke-width:2px;
```
