TreeImagining is an advanced computer vision project that leverages YOLOv8 deep learning models to automatically detect and count trees in aerial imagery. This system is designed to support forest management, environmental conservation, and developmental projects requiring accurate tree enumeration.
- Automate Tree Counting: Replace manual tree counting methods with AI-powered automation
- Improve Accuracy: Reduce human error in tree enumeration using object detection
- Scale Forest Management: Enable rapid processing of large forest areas through aerial imagery
- Support Decision Making: Provide quantitative data for forest conservation and development planning
TreeImagining/
βββ models/ # Production inference models
β βββ app.py # Main inference application
β βββ best.pt # Trained YOLOv8 model (PyTorch)
β βββ best.onnx # Exported ONNX model for deployment
β βββ hello.pt # Additional model checkpoint
β βββ sample/ # Sample test images
β β βββ image1.jpeg
β β βββ image2.jpeg
β βββ results/ # Detection results with bounding boxes
β βββ result_image1.jpg
β βββ result_image2.jpg
β
βββ tree-count-training/ # Model training pipeline
β βββ data/ # Training dataset
β β βββ data.yaml # Dataset configuration
β β βββ train/ # Training images & labels
β β βββ valid/ # Validation images & labels
β β βββ test/ # Testing images & labels
β βββ model-training.ipynb # Interactive training notebook
β βββ train.py # Training script with CLI
β βββ data_prep.py # Dataset preparation utilities
β βββ evaluate.py # Model evaluation metrics
β βββ visualize.py # Visualization utilities
β βββ export.py # Model export (ONNX, TorchScript)
β βββ notebooks/ # Experimental notebooks
β βββ reports/ # Training reports & visualizations
β βββ predictions.html
β βββ viz/
β
βββ env/ # Python virtual environment
βββ requirements.txt # Python dependencies
βββ .gitignore # Git ignore rules
βββ README.md # This file
- Data Acquisition: Aerial/satellite imagery from Roboflow (CC BY 4.0 license)
- Data Preparation: COCO/VOC format conversion to YOLO format
- Data Augmentation: Albumentations library for image transformations
- Dataset Split: 80% train, 10% validation, 10% test
- Base Model: YOLOv8 (You Only Look Once v8)
- Task: Object Detection (Single class: 'tree')
- Input Size: 640x640 pixels
- Confidence Threshold: 0.25
- IoU Threshold: 0.45
# Key Training Parameters
- Model: yolov8n.pt (nano) / yolov8s.pt (small)
- Epochs: 50 (configurable)
- Batch Size: 8
- Image Size: 640x640
- Optimizer: AdamW
- Device: GPU (CUDA) / CPU fallback- Python 3.8+ (Tested on Python 3.13)
- CUDA-capable GPU (optional, but recommended)
- 8GB+ RAM
- Windows/Linux/macOS
- Clone the repository
git clone https://github.com/flyingvaibhav/TreeSensing.git
cd TreeImagining- Create virtual environment
python -m venv env
# Windows
.\env\Scripts\activate
# Linux/Mac
source env/bin/activate- Install dependencies
pip install -r requirements.txtcd models
python app.pyThis will:
- Load the trained
best.ptmodel - Process images in the
sample/folder - Display detection results
- Save annotated images to
results/ - Print tree counts and confidence scores
cd tree-count-training
python train.py --data data/data.yaml --model yolov8n.pt --epochs 50 --batch 8Training Arguments:
--data: Path to data.yaml configuration--model: Pretrained model (yolov8n/s/m/l/x.pt)--epochs: Number of training epochs--batch: Batch size--imgsz: Image size (default: 640)--resume: Resume from checkpoint--wandb: Enable Weights & Biases logging
cd tree-count-training
jupyter notebook model-training.ipynbThe notebook includes:
- Dataset exploration and visualization
- Model training with progress tracking
- Validation metrics and graphs
- Result analysis and predictions
cd tree-count-training
python evaluate.py --model ../models/best.pt --data data/data.yamlMetrics Generated:
- MAE (Mean Absolute Error): Average counting error
- RMSE (Root Mean Squared Error): Prediction accuracy
- RΒ² (R-squared): Model fit quality
- mAP50: Mean Average Precision at IoU=0.50
- mAP50-95: Mean Average Precision at IoU=0.50:0.95
- Precision: True positive rate
- Recall: Detection completeness
Output saved to: counting_report.json
cd tree-count-training
python visualize.py --model ../models/best.pt --data data/data.yaml --out viz_outCreates annotated images with:
- Bounding boxes around detected trees
- Confidence scores for each detection
- Saved to
viz_out/directory
cd tree-count-training
python export.py --weights ../models/best.pt --format onnx --imgsz 640Supported Formats:
onnx: ONNX Runtime (cross-platform deployment)torchscript: TorchScript (PyTorch production)pb: TensorFlow format
cd tree-count-training
# From COCO format
python data_prep.py --coco-json path/to/annotations.json --images path/to/images --dst prepared_data
# From VOC format
python data_prep.py --voc-images path/to/images --voc-anno path/to/annotations --dst prepared_dataCreates YOLO-compatible structure:
prepared_data/
βββ train/
β βββ images/
β βββ labels/
βββ valid/
β βββ images/
β βββ labels/
βββ test/
βββ images/
βββ labels/
Source: Roboflow Universe - Tree Counting Dataset
License: CC BY 4.0
Classes: 1 (tree)
Format: YOLO v8
Split Ratio: 80/10/10 (train/valid/test)
Dataset YAML Configuration:
train: ../train/images
val: ../valid/images
test: ../test/images
nc: 1
names: ['tree']This project is part of the TreeSense Imaging ecosystem - a comprehensive Smart India Hackathon solution for forest management:
- Tree Count: Automated tree enumeration (this project)
- Green Cover Estimator: Calculate vegetation percentage
- Tree Species Identifier: ML-based species classification
- Optimal Pathing: Route planning through forest areas
- Historical Data: Time-series analysis of forest changes
π Full Project: treesense-imaging/
- ultralytics: YOLOv8 implementation
- torch: PyTorch deep learning framework
- opencv-python: Image processing
- numpy: Numerical computations
- pandas: Data manipulation
- torchvision: Vision utilities
- scikit-learn: Evaluation metrics
- albumentations: Data augmentation
- matplotlib: Visualization
- rasterio: Geospatial raster processing
- geopandas: Geospatial data frames
- shapely: Geometric operations
- fastapi: REST API framework
- uvicorn: ASGI server
- celery: Distributed task queue
(Update after training completion)
| Metric | Value |
|---|---|
| mAP50 | TBD |
| mAP50-95 | TBD |
| Precision | TBD |
| Recall | TBD |
| MAE (Count) | TBD |
| RMSE (Count) | TBD |
- Image 1: Detection with bounding boxes saved to
models/results/result_image1.jpg - Image 2: Detection with bounding boxes saved to
models/results/result_image2.jpg
- Forest Conservation: Monitor tree population in protected areas
- Urban Planning: Count trees in city planning projects
- Environmental Impact Assessment: Quantify deforestation/reforestation
- Agricultural Management: Inventory orchard trees
- Carbon Credit Verification: Validate carbon sequestration claims
- Research: Biodiversity and ecosystem studies
1. CUDA Out of Memory
# Reduce batch size
python train.py --batch 4 --imgsz 4162. Model Not Found
# Ensure you're in the correct directory
cd models
ls best.pt # Should exist3. Dataset Path Errors
- Check
data.yamlpaths are relative to the YAML file location - Verify images and labels folders exist
4. Dependencies Issues
# Reinstall dependencies
pip install --upgrade -r requirements.txtContributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit changes (
git commit -m 'Add AmazingFeature') - Push to branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under GNU AGPLv3
Dataset is licensed under CC BY 4.0 (Roboflow)
- Vaibhav - @flyingvaibhav
- TreeSense Team - Smart India Hackathon 2023
- Repository: github.com/flyingvaibhav/TreeSensing
- Issues: Report bugs and feature requests via GitHub Issues
- Ultralytics for YOLOv8 implementation
- Roboflow for dataset hosting and annotation tools
- Smart India Hackathon for project inspiration
- Open Source Community for excellent ML libraries
- YOLOv8 object detection model
- Training pipeline with CLI
- Jupyter notebook training
- Model evaluation metrics
- ONNX export for deployment
- Basic inference application
- Web API with FastAPI
- Real-time video processing
- Multi-model ensemble
- Geospatial coordinate mapping
- Integration with GIS systems
- Mobile app deployment
- Cloud deployment (AWS/Azure)
- Tree species classification
- Tree health assessment
β If you find this project useful, please consider giving it a star!
Last Updated: October 30, 2025