Detectree2

Automatic tree crown delineation based on the Detectron2 implementation of Mask R-CNN.
https://github.com/PatBall1/detectree2

Category: Biosphere
Sub Category: Forest Remote Sensing

Keywords

deep-learning detectron2 python pytorch

Last synced: about 10 hours ago
JSON representation

Repository metadata

Python package for automatic tree crown delineation based on the Detectron2 implementation of Mask R-CNN

README.md

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.

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.

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


Owner metadata


GitHub Events

Total
Last Year

Committers metadata

Last synced: 20 days ago

Total Commits: 404
Total Committers: 11
Avg Commits per committer: 36.727
Development Distribution Score (DDS): 0.396

Commits in past year: 67
Committers in past year: 3
Avg Commits per committer in past year: 22.333
Development Distribution Score (DDS) in past year: 0.418

Name Email Commits
Ball JGC b****c@g****m 244
James Ball j****3@s****k 66
Christopher Kotthoff c****7@r****m 31
James-Hirst-1998 h****j@g****m 24
Matthew Archer m****5@c****k 19
Charles Song c****g@g****m 10
Paul Tresson p****n@c****r 3
Seb Hickman 5****0 2
Puming (Oscar) Jiang 1****g 2
Andrés Camilo Zúñiga-González 3****o 2
ai4er-cookiecutter c****r@h****g 1

Committer domains:


Issue and Pull Request metadata

Last synced: 21 days ago

Total issues: 105
Total pull requests: 125
Average time to close issues: 4 months
Average time to close pull requests: about 2 months
Total issue authors: 30
Total pull request authors: 12
Average comments per issue: 1.67
Average comments per pull request: 0.42
Merged pull request: 84
Bot issues: 0
Bot pull requests: 0

Past year issues: 24
Past year pull requests: 22
Past year average time to close issues: 20 days
Past year average time to close pull requests: 12 days
Past year issue authors: 10
Past year pull request authors: 5
Past year average comments per issue: 1.83
Past year average comments per pull request: 0.86
Past year merged pull request: 12
Past year bot issues: 0
Past year bot pull requests: 0

More stats: https://issues.ecosyste.ms/repositories/lookup?url=https://github.com/PatBall1/detectree2

Top Issue Authors

  • ma595 (29)
  • PatBall1 (21)
  • CiSong10 (9)
  • xabierr (6)
  • ChristopherKotthoff (4)
  • yby026 (3)
  • rjstack266 (3)
  • aloboa (3)
  • DrawingWorkerChi (2)
  • Coder-GAN (2)
  • ancazugo (2)
  • chenyuanyuan12138 (2)
  • Joda0515 (2)
  • Leprechault (1)
  • ambarwariagus (1)

Top Pull Request Authors

  • PatBall1 (40)
  • ChristopherKotthoff (34)
  • ma595 (22)
  • 0scarJ1ang (7)
  • CiSong10 (7)
  • WangLuran (4)
  • James-Hirst-1998 (4)
  • Dseal95 (2)
  • ancazugo (2)
  • TeddyLiang01 (1)
  • mpcabete (1)
  • ptresson (1)

Top Issue Labels

  • enhancement (11)
  • bug (6)
  • build (6)
  • documentation (4)
  • testing (1)
  • performance (1)
  • help wanted (1)
  • wontfix (1)

Top Pull Request Labels

  • build (4)
  • documentation (3)
  • enhancement (1)

Package metadata

proxy.golang.org: github.com/patball1/detectree2

  • Homepage:
  • Documentation: https://pkg.go.dev/github.com/patball1/detectree2#section-documentation
  • Licenses: mit
  • Latest release: v2.1.1+incompatible (published 5 months ago)
  • Last Synced: 2026-02-13T22:48:05.293Z (about 1 month ago)
  • Versions: 11
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent packages count: 5.395%
    • Average: 5.576%
    • Dependent repos count: 5.758%
proxy.golang.org: github.com/PatBall1/detectree2

  • Homepage:
  • Documentation: https://pkg.go.dev/github.com/PatBall1/detectree2#section-documentation
  • Licenses: mit
  • Latest release: v2.1.2+incompatible (published about 1 month ago)
  • Last Synced: 2026-02-15T09:16:54.187Z (about 1 month ago)
  • Versions: 12
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent packages count: 5.395%
    • Average: 5.576%
    • Dependent repos count: 5.758%
pypi.org: detectree2

Detectree packaging

  • Homepage: https://github.com/PatBall1/detectree2
  • Documentation: https://detectree2.readthedocs.io/
  • Licenses: mit
  • Latest release: 0.0.1 (published over 3 years ago)
  • Last Synced: 2026-02-13T16:13:49.996Z (about 1 month ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 31 Last month
  • Rankings:
    • Dependent packages count: 6.633%
    • Forks count: 10.336%
    • Stargazers count: 15.288%
    • Average: 24.269%
    • Dependent repos count: 30.611%
    • Downloads: 58.475%
  • Maintainers (1)

Dependencies

.github/workflows/docker-test.yml actions
  • GuillaumeFalourd/clone-github-repo-action v2 composite
  • actions/checkout v3 composite
.github/workflows/python-ci.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v3 composite
.github/workflows/sphinx-ci.yml actions
  • actions/checkout v3 composite
  • actions/upload-artifact v3 composite
  • peaceiris/actions-gh-pages v3 composite
docker/Dockerfile docker
  • nvidia/cuda 11.1.1-cudnn8-devel-ubuntu20.04 build
docs/requirements.txt pypi
  • jinja2 ==3.0.3
requirements/dev-requirements.txt pypi
  • black * development
  • flake8 * development
  • flake8-docstrings * development
  • isort * development
  • mypy * development
  • python-dotenv * development
requirements/requirements.txt pypi
  • Fiona ==1.8.21
  • Markdown ==3.3.6
  • Pillow ==9.0.1
  • PyCRS ==1.0.2
  • PyYAML ==5.1
  • Rtree ==0.9.7
  • Shapely ==1.8.1.post1
  • Werkzeug ==2.0.3
  • absl-py ==1.0.0
  • affine ==2.3.0
  • antlr4-python3-runtime ==4.8
  • appdirs ==1.4.4
  • attrs ==21.4.0
  • black ==21.4b2
  • cachetools ==5.0.0
  • certifi ==2021.10.8
  • charset-normalizer ==2.0.12
  • click ==8.0.4
  • click-plugins ==1.1.1
  • cligj ==0.7.2
  • cloudpickle ==2.0.0
  • cycler ==0.11.0
  • descartes ==1.1.0
  • detectron2 ==0.6
  • flake8 ==4.0.1
  • fonttools ==4.30.0
  • future ==0.18.2
  • fvcore ==0.1.5.post20220305
  • geopandas ==0.10.2
  • google-auth ==2.6.0
  • google-auth-oauthlib ==0.4.6
  • grpcio ==1.44.0
  • hydra-core ==1.1.1
  • idna ==3.3
  • importlib-metadata ==4.11.3
  • importlib-resources ==5.4.0
  • iopath ==0.1.9
  • kiwisolver ==1.4.0
  • matplotlib ==3.5.1
  • mccabe ==0.6.1
  • munch ==2.5.0
  • mypy-extensions ==0.4.3
  • numpy ==1.22.3
  • oauthlib ==3.2.0
  • omegaconf ==2.1.1
  • opencv-python ==4.5.5.64
  • packaging ==21.3
  • pandas ==1.4.1
  • pathspec ==0.9.0
  • portalocker ==2.4.0
  • protobuf ==3.19.4
  • pyasn1 ==0.4.8
  • pyasn1-modules ==0.2.8
  • pycocotools ==2.0.4
  • pycodestyle ==2.8.0
  • pydot ==1.4.2
  • pyflakes ==2.4.0
  • pygeos ==0.12.0
  • pyparsing ==3.0.7
  • pypng ==0.0.21
  • pyproj ==3.3.0
  • pytz ==2021.3
  • rasterio ==1.2.10
  • regex ==2022.3.15
  • requests ==2.27.1
  • requests-oauthlib ==1.3.1
  • rsa ==4.8
  • snuggs ==1.4.7
  • tabulate ==0.8.9
  • tensorboard ==2.8.0
  • tensorboard-data-server ==0.6.1
  • tensorboard-plugin-wit ==1.8.1
  • termcolor ==1.1.0
  • toml ==0.10.2
  • torch ==1.9.0
  • torchvision ==0.10.0
  • tqdm ==4.63.0
  • typing_extensions ==4.1.1
  • urllib3 ==1.26.9
  • yacs ==0.1.8
  • zipp ==3.7.0
requirements/test-requirements.txt pypi
  • click * test
  • coverage * test
  • flake8 * test
  • python-dotenv * test
  • sphinx * test
  • virtualenv * test
setup.py pypi
  • GDAL >=1.11
  • descartes *
  • detectron2 *
  • fiona *
  • geopandas *
  • geos *
  • proj *
  • pycrs *
  • pygeos *
  • pypng *
  • pyyaml ==5.1
  • rasterio ==1.3a3
requirements/environment.yml pypi
  • hydra-core *

Score: 11.523113391357718