Science Score: 59.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 1 DOI reference(s) in README
  • Academic publication links
    Links to: zenodo.org
  • Committers with academic emails
    1 of 5 committers (20.0%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (14.0%) to scientific vocabulary
Last synced: 7 months ago · JSON representation

Repository

Basic Info
  • Host: GitHub
  • Owner: open-forest-observatory
  • License: bsd-3-clause
  • Language: Jupyter Notebook
  • Default Branch: main
  • Size: 97.3 MB
Statistics
  • Stars: 23
  • Watchers: 6
  • Forks: 2
  • Open Issues: 25
  • Releases: 2
Created over 1 year ago · Last pushed 7 months ago
Metadata Files
Readme Contributing License

README.md

tree-detection-framework

This project has three main goals: * Enable tree detection on realistic-scale, geospatial raster data with minimal boilerplate, using existing (external) tree detection/segmentation models * Facilitate direct comparison of multiple algorithms * Rely on modern libraries and software best practice for a robust, performant, and modular tool

This project does not, itself, provide tree detection/segmentation algorithms (with the exception of a geometric algorithm). Instead, it provides a standardized interface for performing training, inference, and evaluation using existing tree detection models and algorithms. The project currently supports the external computer vision models DeepForest, Dectree2, and SAM2, as well as a geometric canopy height model segmentor implemented within TDF. Support for other external models can be added by implementing a new Detector class.

We use the torchgeo package to perform data loading and standardization using standard geospatial input formats. This library allows us to generate chips on the fly of a given size, stride, and spatial resolution. Training and inference is done with modular detectors that can be based on existing models and algorithms. We have preliminary support for using PyTorch Lightning to minimize boilerplate around model training and prediction. Region-level nonmax-suppression (NMS) is done using the PolyGoneNMS library which is efficient for large images. Visualization and saving of the predictions is done using geopandas, a common library for geospatial data.

This project is under active development by the Open Forest Observatory. We welcome contributions and suggestions for improvement.

Tree detection models supported

TDF currently supports the following tree detection/segmentation algorithms.

DeepForest

  • Github
  • Uses RGB input data. Predicts tree crowns with rectangular bounding boxes.
  • Provides a RetinaNet model trained on a large number of semi-supervised tree crown annotations and a smaller set of manual annotations.
  • Trained using data from the US only but representing diverse regions. The model has been applied on data from outside the US successfully.

Detectree2

  • Github
  • Uses RGB input data. Predicts tree crowns with polygon boundaries.
  • Provides a Mask R-CNN model trained on manually labeled tree crowns from four sites.
  • Trained using data from tropical forests.

Segment Anything Model 2 (SAM2)

  • Github
  • Uses RGB input data. Predicts objects with polygon boundaries.
  • Utilizes the Segment Anything Model (SAM 2.1 Hiera Large) checkpoint with tuned parameters for mask generation optimized for tree crown delineation.
  • Does not rely on supervised training for tree-specific data but generalizes well due to SAM's zero-shot nature; however, non-tree objects are also detected and included in predictions.

Geometric Detector

  • Implementation of the variable window filter algorithm of Popescu and Wynne (2004) for tree top detection, combined with the algorithm of Silva et al. (2016) for crown segmentation.
  • Uses canopy height model (CHM) input data. Predicts tree crowns with polygon boundaries.
  • This is a learning-free tree detection algorithm. It is the one algorithm that is implemented within TDF as opposed to relying on an existing external model/algorithm.

Software architecture

The tree-detection-framework is organized into modular components to facilitate extension including integration of additional detection models. The main components are:

  1. preprocessing.py
    The create_dataloader() method accepts single/multiple orthomosaic inputs. Alternatively, create_image_datalaoder() accepts a folder containing raw drone imagery. The methods tile the input images based on user-specified parameters such as tile size, stride, and resolution and return a PyTorch-compatible dataloader for inference.
  2. Detector Base Class
    All detectors in the framework (e.g., DeepForestDetector, Detectree2Detector) inherit from the Detector base class. The base class defines the core logic for generating predictions and geospatially referencing image tiles, while model-specific detectors translate the inputs to the format expected by the respective model. This design allows all detectors to plug into the same pipeline with minimal code changes.
  3. RegionDetectionsSet and RegionDetections
    These classes standardize model outputs. A RegionDetectionsSet is a collection of RegionDetections, where each RegionDetections object represents the detections in a single image tile. This abstraction allows postprocessing components to operate uniformly across different detectors. These outputs can be saved out as .gpkg or .geojson files.
  4. postprocessing.py
    Impelments a set of postprocessing functions for cleaning the detections by Non-Maximum Suppression(NMS), polygon hole suppression, tile boundary suppression, and removing out of bounds detections. Most of these methods operate on standardized output types (RegionDetections / RegionDetectionsSet).

Install

Some of the dependencies are managed by a tool called Poetry. I've found easiest to install this using the "official installer" option as follows. Note that this should be run in the base conda environment or with no environment active. curl -sSL https://install.python-poetry.org | python3 - Now create and activate a conda environment for the dependencies of this project. conda create -n tree-detection-framework python=3.10 -y conda activate tree-detection-framework

Now, from the root directory of the project, run the following command. Note that on Jetstream2, you may need to run this in a graphical session and respond to a keyring popup menu. poetry install Finally, choose to either install the Detectron2 or SAM2 detection framework.

Detectron2: The Detectron2 library is not compatible with poetry so must be installed directly with pip ```

https://detectron2.readthedocs.io/en/latest/tutorials/install.html#build-detectron2-from-source

pip install git+https://github.com/facebookresearch/detectron2.git Download the detectree2 checkpoint weights. cd checkpoints mkdir detectree2 cd detectree2 wget https://zenodo.org/records/10522461/files/230103randresizefull.pth **SAM2:** Clone the SAM2 repository and install the necessary config files git clone https://github.com/facebookresearch/sam2.git && cd sam2

pip install -e . And download the associated checkpoints cd checkpoints && \ ./download_ckpts.sh && \ cd .. And move into this repo mv checkpoints ../tree-detection-framework ```

Use

The module code is in the tree_detection_framework folder. Once installed using the poetry command above, this code can be imported into scripts or notebooks under the name tree_detection_framework the same as you would for any other library.

Examples

To begin with, you can access example geospatial data here, which should be downloaded and placed in the data folder at the top level of this project. Our goal is to have high-quality, up-to-date examples in the examples folder. We also have work-in-progress or one-off code in sandbox, which still may provide some insight but is not guaranteed to be current or generalizable. Finally, the tree_detection_framework/entrypoints folder has command line scripts that can be run to complete tasks.

Evaluation and benchmark with NEON

Download the NEON dataset files and save the annotations and RGB folders under a new directory in the data folder. wget -O annotations.zip "https://zenodo.org/records/5914554/files/annotations.zip?download=1" unzip annotations.zip wget -O evaluation.zip "https://zenodo.org/records/5914554/files/evaluation.zip?download=1" unzip -j evaluation.zip "evaluation/RGB/*" -d RGB rm annotations.zip rm evaluation.zip Follow the steps in tree-detection-framework/sandbox/evaluation/neon_benchmark.ipynb for detectors DeepForest & Detectree2, and tree-detection-framework/sandbox/evaluation/sam2_neon_benchmark.ipynb to use SAM2.

Evaluation and benchmark with Detectree2 datasets

  1. Download the dataset. There are two ways to get the dataset: Download the site-specific .tif (for orthomosaic) and .gpkg (for ground truth polygons) files from https://zenodo.org/records/8136161. Then, follow steps in https://github.com/PatBall1/detectree2/blob/master/notebooks/colab/tilingJB.ipynb to do the the tiling. (OR) Download our pre-tiled dataset from https://ucdavis.box.com/s/thjmaane9d38opw1bhnyxrsrtt90j37m
  2. Add the tiled dataset folder to the data folder in this repo.
  3. For benchmark and evaluation see steps in tree-detection-framework/sandbox/evaluation/dtree2_benchmark.ipynb and tree-detection-framework/sandbox/evaluation/sam2_dtree2_benchmark.ipynb

Owner

  • Name: Open Forest Observatory
  • Login: open-forest-observatory
  • Kind: organization
  • Email: openforestobservatory@ucdavis.edu

OFO is developing easy-to-use software tools for drone-based forest mapping and a database of tree maps produced from drone imagery

GitHub Events

Total
  • Create event: 63
  • Release event: 1
  • Issues event: 83
  • Watch event: 21
  • Delete event: 54
  • Member event: 1
  • Issue comment event: 95
  • Push event: 401
  • Pull request event: 115
  • Pull request review event: 271
  • Pull request review comment event: 321
  • Fork event: 1
Last Year
  • Create event: 63
  • Release event: 1
  • Issues event: 83
  • Watch event: 21
  • Delete event: 54
  • Member event: 1
  • Issue comment event: 95
  • Push event: 401
  • Pull request event: 115
  • Pull request review event: 271
  • Pull request review comment event: 321
  • Fork event: 1

Committers

Last synced: 7 months ago

All Time
  • Total Commits: 573
  • Total Committers: 5
  • Avg Commits per committer: 114.6
  • Development Distribution Score (DDS): 0.337
Past Year
  • Commits: 573
  • Committers: 5
  • Avg Commits per committer: 114.6
  • Development Distribution Score (DDS): 0.337
Top Committers
Name Email Commits
Amritha a****2@g****m 380
David Russell d****l@u****u 136
Eric Schneider f****r@g****m 37
mich889 m****9 12
Derek Young 2****n 8
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 7 months ago

All Time
  • Total issues: 63
  • Total pull requests: 131
  • Average time to close issues: 15 days
  • Average time to close pull requests: 2 days
  • Total issue authors: 7
  • Total pull request authors: 5
  • Average comments per issue: 0.57
  • Average comments per pull request: 0.79
  • Merged pull requests: 116
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 63
  • Pull requests: 131
  • Average time to close issues: 15 days
  • Average time to close pull requests: 2 days
  • Issue authors: 7
  • Pull request authors: 5
  • Average comments per issue: 0.57
  • Average comments per pull request: 0.79
  • Merged pull requests: 116
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • russelldj (44)
  • amrithasp02 (10)
  • youngdjn (6)
  • chugom77 (1)
  • FranzEricSchneider (1)
  • bw4sz (1)
  • jeffgillan (1)
Pull Request Authors
  • amrithasp02 (64)
  • russelldj (60)
  • FranzEricSchneider (7)
  • youngdjn (4)
  • mich889 (2)
Top Labels
Issue Labels
enhancement (9) bug (1)
Pull Request Labels
enhancement (2)

Dependencies

.github/workflows/black.yml actions
  • actions/checkout v3 composite
  • psf/black stable composite
  • stefanzweifel/git-auto-commit-action v4 composite
.github/workflows/isort.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v2 composite
  • stefanzweifel/git-auto-commit-action v5 composite
poetry.lock pypi
  • 137 dependencies
pyproject.toml pypi
  • deepforest ^1.3.3
  • lsnms ^0.4.4
  • python >=3.10,<3.12
  • torchgeo ^0.6.0