Automatic tree crown delineation in aerial RGB imagery based on Mask R-CNN.
Project description
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.
| 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
- Python 3.8+
- GDAL geospatial libraries
- PyTorch >= 1.8 and torchvision (matching versions)
- Detectron2 (Facebook's object detection library)
- For training models, GPU access (with CUDA) is recommended
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:
- Tile the orthomosaics and crown data (for training, validation and testing)
- Train (and tune) a model on the training tiles
- Evaluate the model performance by predicting on the test tiles and comparing to manual crowns for the tiles
- 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.
Here is an example image of the predictions made by Detectree2.
Applications
Tracking tropical tree growth and mortality
Counting urban trees (Buffalo, NY)
Multi-temporal tree crown segmentation
Liana detection and infestation mapping
In development
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2c6a08a394682fd0674aaf9c1a7698dde56e834c8aba9629ae131063dcec8801
|
|
| MD5 |
a3698b9241b41d2129bcb013e52fba5d
|
|
| BLAKE2b-256 |
59475a1136e3d14763c2fd5bd64347beb507da6b8d84a4235013dbfe8275aade
|
Provenance
The following attestation bundles were made for detectree2-2.1.2.tar.gz:
Publisher:
publish.yml on PatBall1/detectree2
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
detectree2-2.1.2.tar.gz -
Subject digest:
2c6a08a394682fd0674aaf9c1a7698dde56e834c8aba9629ae131063dcec8801 - Sigstore transparency entry: 953215910
- Sigstore integration time:
-
Permalink:
PatBall1/detectree2@d9fb07f0dfb493f34def563c1ff896fecd59210d -
Branch / Tag:
refs/tags/v2.1.2 - Owner: https://github.com/PatBall1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d9fb07f0dfb493f34def563c1ff896fecd59210d -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
25dca2e25e81420a874e43ce20e8b7a23caa5854be5df663a6831d5cd8b2e0ce
|
|
| MD5 |
cdb117e668e80b1c4cdaa6bafa3c44b2
|
|
| BLAKE2b-256 |
d19d6f7dc9fbf6413fc3cef08c45efb8d5d6772024a10c32ce91c6db51492562
|
Provenance
The following attestation bundles were made for detectree2-2.1.2-py3-none-any.whl:
Publisher:
publish.yml on PatBall1/detectree2
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
detectree2-2.1.2-py3-none-any.whl -
Subject digest:
25dca2e25e81420a874e43ce20e8b7a23caa5854be5df663a6831d5cd8b2e0ce - Sigstore transparency entry: 953215912
- Sigstore integration time:
-
Permalink:
PatBall1/detectree2@d9fb07f0dfb493f34def563c1ff896fecd59210d -
Branch / Tag:
refs/tags/v2.1.2 - Owner: https://github.com/PatBall1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d9fb07f0dfb493f34def563c1ff896fecd59210d -
Trigger Event:
release
-
Statement type: