Skip to main content

Automatic tree crown delineation in aerial RGB imagery based on Mask R-CNN.

Project description

predictions predictions

PyPI License: MIT Detectree CI PEP8 DOI Open in Spaces

Python package for automatic tree crown delineation in aerial RGB and multispectral imagery based on Mask R-CNN. Pre-trained models can be picked in the model_garden. Tutorials on how to prepare data, train models and make predictions are available here. For questions, collaboration proposals and requests for data email James Ball. Some example data is available to download here.

Detectree2是一个基于Mask R-CNN的自动树冠检测与分割的Python包。您可以在model_garden中选择预训练模型。这里提供了如何准备数据、训练模型和进行预测的教程。如果有任何问题,合作提案或者需要样例数据,可以邮件联系James Ball。一些示例数据可以在这里下载。

🌳 Want a quick taster of what detectree2 can do?

Upload a sample of your aerial imagery and see tree crown predictions in seconds — no install, no code, no GPU required. Get a feel for the results before diving into the full package.

Try the Online Demo

Code developed by James Ball, Seb Hickman, Christopher Kotthoff, Thomas Koay, Oscar Jiang, Luran Wang, Panagiotis Ioannou, James Hinton and Matthew Archer in the Forest Ecology and Conservation Group at the University of Cambridge. The Forest Ecology and Conservation Group is led by Professor David Coomes and is part of the University of Cambridge Conservation Research Institute.
Supported by forestmap.ai.

Citation

Please cite this article if you use detectree2 in your work:

Ball, J.G.C., Hickman, S.H.M., Jackson, T.D., Koay, X.J., Hirst, J., Jay, W., Archer, M., Aubry-Kientz, M., Vincent, G. and Coomes, D.A. (2023), Accurate delineation of individual tree crowns in tropical forests from aerial RGB imagery using Mask R-CNN. Remote Sens Ecol Conserv. 9(5):641-655. https://doi.org/10.1002/rse2.332

Independent validation

Independent validation has been performed on a temperate deciduous forest in Japan.

Detectree2 (F1 score: 0.57) outperformed DeepForest (F1 score: 0.52)

Detectree2 could estimate tree crown areas accurately, highlighting its potential and robustness for tree detection and delineation

Gan, Y., Wang, Q., and Iio, A. (2023). Tree Crown Detection and Delineation in a Temperate Deciduous Forest from UAV RGB Imagery Using Deep Learning Approaches: Effects of Spatial Resolution and Species Characteristics. Remote Sensing. 15(3):778. https://doi.org/10.3390/rs15030778

Requirements

Installation

Step 1: Install PyTorch

Follow the official instructions to install PyTorch with the appropriate CUDA version for your system:

# Example: CPU-only
pip install torch torchvision torchaudio

# Example: CUDA 12.4
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124

Step 2: Install Detectron2

pip install 'git+https://github.com/facebookresearch/detectron2.git'

Step 3: Install detectree2

pip install detectree2

Or install from source for development:

git clone https://github.com/PatBall1/detectree2.git
cd detectree2
pip install -e ".[dev,test]"

Note: If you have trouble with geospatial dependencies (GDAL, rasterio, fiona), using conda to install them first is recommended: conda install -c conda-forge gdal rasterio fiona. See Installation Instructions for more details.

Getting started

Detectree2, based on the Detectron2 Mask R-CNN architecture, locates trees in aerial images. It has been designed to delineate trees in challenging dense tropical forests for a range of ecological applications.

This tutorial takes you through the key steps. Example Colab notebooks are also available but are not updated frequently so functions and parameters may need to be adjusted to get things working properly.

The standard workflow includes:

  1. Tile the orthomosaics and crown data (for training, validation and testing)
  2. Train (and tune) a model on the training tiles
  3. Evaluate the model performance by predicting on the test tiles and comparing to manual crowns for the tiles
  4. Using the trained model to predict the crowns over the entire region of interest

Training crowns are used to teach the network to delineate tree crowns.

predictions predictions

Here is an example image of the predictions made by Detectree2.

predictions

Applications

Tracking tropical tree growth and mortality

predicting

Counting urban trees (Buffalo, NY)

predicting

Multi-temporal tree crown segmentation

predicting

Liana detection and infestation mapping

In development

predicting

Tree species identification and mapping

In development

To do

  • Functions for multiple labels vs single "tree" label

Project Organization

├── .github/                 # CI workflows, badges and logos
│   └── workflows/
├── CODE_OF_CONDUCT.md
├── LICENSE
├── Makefile
├── README.md
├── detectree2/              # Python package (models, data loading, preprocessing, tests, etc.)
│   ├── data_loading/
│   ├── models/
│   ├── preprocessing/
│   ├── R/
│   └── tests/
├── docker/                  # Container recipe for reproducible builds
│   └── Dockerfile
├── docs/                    # Sphinx documentation sources
│   └── source/
├── model_garden/            # Pre-trained model metadata
├── notebooks/               # Exploratory, Colab, and Turing workflows
│   ├── colab/
│   ├── exploratory/
│   ├── reports/
│   └── turing/
├── report/                  # Paper figures and manuscript sections
│   ├── figures/
│   └── sections/
├── requirements/            # Runtime, test, and dev requirement files
│   ├── requirements.txt
│   ├── dev-requirements.txt
│   └── test-requirements.txt
├── pyproject.toml           # Package config, deps, tool settings
└── .setup_scripts/          # Helper scripts for local tooling

Code formatting

We rely on the pre-commit hooks defined in .pre-commit-config.yaml to keep formatting, linting, and type checking consistent (yapf, isort, flake8, and mypy share the configuration in setup.cfg).

python -m pip install pre-commit -r requirements/dev-requirements.txt
pre-commit install
pre-commit run --all-files

If you need to run the tools individually you can use:

yapf -ir detectree2
isort detectree2
flake8 detectree2
mypy detectree2

Copyright (c) 2022, James G. C. Ball

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

detectree2-2.1.2.tar.gz (321.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

detectree2-2.1.2-py3-none-any.whl (318.9 kB view details)

Uploaded Python 3

File details

Details for the file detectree2-2.1.2.tar.gz.

File metadata

  • Download URL: detectree2-2.1.2.tar.gz
  • Upload date:
  • Size: 321.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for detectree2-2.1.2.tar.gz
Algorithm Hash digest
SHA256 2c6a08a394682fd0674aaf9c1a7698dde56e834c8aba9629ae131063dcec8801
MD5 a3698b9241b41d2129bcb013e52fba5d
BLAKE2b-256 59475a1136e3d14763c2fd5bd64347beb507da6b8d84a4235013dbfe8275aade

See more details on using hashes here.

Provenance

The following attestation bundles were made for detectree2-2.1.2.tar.gz:

Publisher: publish.yml on PatBall1/detectree2

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file detectree2-2.1.2-py3-none-any.whl.

File metadata

  • Download URL: detectree2-2.1.2-py3-none-any.whl
  • Upload date:
  • Size: 318.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for detectree2-2.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 25dca2e25e81420a874e43ce20e8b7a23caa5854be5df663a6831d5cd8b2e0ce
MD5 cdb117e668e80b1c4cdaa6bafa3c44b2
BLAKE2b-256 d19d6f7dc9fbf6413fc3cef08c45efb8d5d6772024a10c32ce91c6db51492562

See more details on using hashes here.

Provenance

The following attestation bundles were made for detectree2-2.1.2-py3-none-any.whl:

Publisher: publish.yml on PatBall1/detectree2

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page