Skip to content

A machine learning project for predicting vegetation index values using deep learning models exported to ONNX format. This project focuses on temporal vegetation analysis, predicting summer NDVI values from spring satellite imagery.

Notifications You must be signed in to change notification settings

EgemenErin/VegetationIndexRegressionONNX

Repository files navigation

Vegetation Index Regression ONNX

A machine learning project for predicting vegetation index values using deep learning models exported to ONNX format. This project focuses on temporal vegetation analysis, predicting summer NDVI values from spring satellite imagery.

Project Overview

This project implements a regression model that predicts summer vegetation index (NDVI) values from spring satellite imagery. The model is trained using satellite data spanning multiple years (2017-2024) and is designed to help with agricultural planning and vegetation monitoring.

Features

  • Multi-temporal Analysis: Uses spring satellite imagery to predict summer NDVI values
  • ONNX Export: Models are exported to ONNX format for cross-platform deployment
  • Metadata Integration: ONNX models include comprehensive metadata for deployment
  • Tiled Processing: Supports processing of large satellite images through tiling
  • Multi-year Training Data: Includes data from 2017-2024 for robust training

Project Structure

├── addmetadata.py              # Adds metadata to ONNX models
├── convert_to_onnx.py          # Converts trained models to ONNX format
├── create_dummy_data.py        # Creates dummy data for testing
├── regressiontrain.py          # Main training script for regression model
├── data/                       # Raw satellite imagery data
│   ├── input_images/           # Spring satellite images (2017-2024)
│   ├── target_images/          # Summer NDVI target images
│   ├── train.py               # Data processing script
│   └── trainingscript         # Training configuration
├── images/all/                 # Processed tile images (40 tiles)
├── labels/all/                 # Corresponding label tiles
├── runs/train/exp1/           # Training outputs and model artifacts
│   ├── best_model.pt          # Best trained PyTorch model
│   ├── model.onnx             # Exported ONNX model
│   ├── config.yaml            # Training configuration
│   └── tensorboard/           # TensorBoard logs
├── train.txt                  # Training data split
├── val.txt                    # Validation data split
└── test.txt                   # Test data split

Model Specifications

  • Model Type: Segmentation/Regression model
  • Input Resolution: 21m spatial resolution
  • Tile Size: 512x512 pixels
  • Tile Overlap: 15 pixels
  • Segmentation Threshold: 0.5
  • Small Segment Filter: 11 pixels minimum
  • Classes:
    • 0: not_road
    • 1: road

Getting Started

Prerequisites

pip install torch torchvision
pip install onnx onnxruntime
pip install rasterio numpy
pip install tensorboard

Training

  1. Prepare your data: Place spring satellite images in data/input_images/ and summer NDVI targets in data/target_images/

  2. Run training:

python regressiontrain.py
  1. Convert to ONNX:
python convert_to_onnx.py
  1. Add metadata:
python addmetadata.py

Data Format

  • Input Images: Spring satellite imagery in TIFF format
  • Target Images: Summer NDVI values in TIFF format
  • Naming Convention:
    • Input: spring_input_YYYY.tif
    • Target: summer_target_ndvi_YYYY.tif

Model Output

The trained model outputs:

  • best_model.pt: PyTorch model checkpoint
  • model.onnx: ONNX model for deployment
  • model_with_metadata.onnx: ONNX model with embedded metadata

Usage

Loading the ONNX Model

import onnx
import onnxruntime as ort

# Load model with metadata
model_path = "model_with_metadata.onnx"
session = ort.InferenceSession(model_path)

# Get model metadata
model = onnx.load(model_path)
metadata = {prop.key: prop.value for prop in model.metadata_props}
print("Model metadata:", metadata)

Inference

# Prepare input data (example)
input_data = preprocess_satellite_image("spring_image.tif")

# Run inference
outputs = session.run(None, {"input": input_data})
predicted_ndvi = outputs[0]

Training Results

Training logs and metrics are available in:

  • runs/train/exp1/tensorboard/: TensorBoard logs
  • runs/train/exp1/training_*.log: Training logs

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Submit a pull request

License

This project is available under the MIT License.

Citation

If you use this work in your research, please cite:

@misc{vegetationindex2024,
  title={Vegetation Index Regression using ONNX},
  author={Your Name},
  year={2024},
  url={https://github.com/EgemenErin/VegetationIndexRegressionONNX}
}

Contact

For questions or collaborations, please open an issue on GitHub.

About

A machine learning project for predicting vegetation index values using deep learning models exported to ONNX format. This project focuses on temporal vegetation analysis, predicting summer NDVI values from spring satellite imagery.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages