Tree crown delineation using detectreeRGB

Forest Modelling Standard Python

license binder render review

RoHub doi

Context

Purpose

Accurately delineating trees using detectron2, a library that provides state-of-the-art deep learning detection and segmentation algorithms.

Modelling approach

An established deep learning model, Mask R-CNN was deployed from detectron2 library to delineate tree crowns accurately. A pre-trained model, named detectreeRGB, is provided to predict the location and extent of tree crowns from a top-down RGB image, captured by drone, aircraft or satellite. detectreeRGB was implemented in python 3.8 using pytorch v1.7.1 and detectron2 v0.5. Further details can be found in the repository documentation.

Highlights

  • detectreeRGB advances the state-of-the-art in tree identification from RGB images by delineating exactly the extent of the tree crown.

  • We demonstrate how to apply the pretrained model to a sample image fetched from a Zenodo repository.

  • Our pre-trained model was developed using aircraft images of tropical forests in Malaysia.

  • The model can be further trained using the user’s own images.

Contributions

Notebook

  • Sebastian H. M. Hickman (author), University of Cambridge, @shmh40

  • Alejandro Coca-Castro (reviewer), The Alan Turing Institute, @acocac

Modelling codebase

  • Sebastian H. M. Hickman (author), University of Cambridge @shmh40

  • James G. C. Ball (contributor), University of Cambridge @PatBall1

  • David A. Coomes (contributor), University of Cambridge

  • Toby Jackson (contributor), University of Cambridge

Modelling funding

The project was supported by the UKRI Centre for Doctoral Training in Application of Artificial Intelligence to the study of Environmental Risks (AI4ER) (EP/S022961/1).

Note

The authors acknowledge the authors of the Detectron2 package which provides the Mask R-CNN architecture.

Load libraries

import cv2
from PIL import Image
import os
import numpy as np
import urllib.request
import glob

# intake library and plugin
import intake
from intake_zenodo_fetcher import download_zenodo_files_for_entry

# geospatial libraries
import geopandas as gpd

from rasterio.transform import from_origin
import rasterio.features

import fiona

from shapely.geometry import shape, mapping, box
from shapely.geometry.multipolygon import MultiPolygon

# machine learning libraries
from detectron2 import model_zoo
from detectron2.engine import DefaultPredictor
from detectron2.utils.visualizer import Visualizer, ColorMode
from detectron2.config import get_cfg
from detectron2.engine import DefaultTrainer

# visualisation
import holoviews as hv
import geoviews.tile_sources as gts
import matplotlib.pyplot as plt

import hvplot.pandas
import hvplot.xarray

import warnings
warnings.filterwarnings(action='ignore')

hv.extension('bokeh', width=100)