Skip to content

Image Object Detection ‐ Deep Forest

Jeffrey K Gillan edited this page Sep 18, 2024 · 39 revisions

Workshops sessions are recorded and posted to the UA Datalab Youtube Channel about 1 week after the live session.

DeepForest Summary

DeepForest is a python library built for identifying tree crowns (and birds) from high-resolution imagery. It works well with drone imagery and high resolution airplane imagery.

DeepForest provides a pre-trained model capable of identifying many types of trees. However, it may not work perfectly in your area of interest. It may produce false positives (ie, objects that are not actually trees) and false negatives (ie, fail to identify all trees in an image). To improve the pre-trained model, users can incorporate their own training data to fine-tune the model to identify your specific trees of interest.


The images above show a drone image of a golf course and the DeepForest pre-trained model applied to detect trees.



How DeepForest Works

DeepForest uses a deep learning convolutional neural network algorithm to identify and put bounding boxes around predicted tree crowns. The algorithm is built using torchvision, which is part of the python library PyTorch.

DeepForest uses RetinaNet, which is one stage object detection model. RetinaNet consists of two major components, 1. a pre-trained convolutional neural network called ResNet50 and 2. a feature pyramid network (FPN). For a deeper look at the model architecture, please see this article.



The Power of CNNs

A convolutional neural network can be trained to identify objects in an image analogously to how humans can identify objects. For example, look at the aerial images of tree species above. The human brain can easily tell that these are probably 3 distinct tree species (from left to right: ponderosa pine, mesquite, willow). We can look at features such as crown shape and leaf architecture to help us identify a tree. For a computer, however, this is very challenging.

Traditional image analysis approaches such as looking at color values of individual pixels or grouping adjacent pixels based on similar values (i.e., objects), will both likely to fail at the task of identifying trees in high-resolution images.

Please watch these VERY useful videos to understand how Convolutional Neural Networks operate:


CNN models can take a few different approaches to image classification. Deepforest specifically carries out object detection.




Jupyter Notebook Example

I have pre-written python code in a Jupyter Notebook that will you show:

  1. How to apply the pre-trained DeepForest model on imagery to identify trees

  2. How to bring in training data from which to fine-tune the model to better fit the trees you are trying to identify

  3. How to start a training run using GPU computing resources

  4. How to output and assess the quality of the prediction model

  5. How to upload your fine-tuned model to Hugging Face


Run the Jupyter Notebook in Google Colab

One option to run the notebook is in Google Colab. This is probably the easiest option to get started. Google provides you with a virtual machine with optional (but limited) GPU resources. Open Colab Notebook


Run the Jupyter Notebook in Cyverse

Cyverse is an excellent place for scientific analysis and data storage and is meant to be a resource for University of Arizona personnel. To run DeepForest on a Cyverse hosted jupyter notebook, users must have an account with Cyverse.


  1. Click this button

  1. Click through the notebook launch sequence and choose the computing resources you would like to use.

  1. Once Jupyter has been launched, go to File >>> Open from URL. Paste the following URL: https://raw.githubusercontent.com/ua-datalab/Geospatial_Workshops/main/notebooks/deepforest_cyverse.ipynb



Label Imagery for Training

Labeling training data can be done on georeferenced or non-georeferenced imagery. For georeferenced imagery, we will use QGIS for the labeling.



  1. With QGIS launched, add the georeferenced image into display: Layer >>> Add Layer >>> Add Raster Layer


  1. Right Click somewhere on the toolbars and turn on Shape Digitizing Toolbar


  1. Create a New Shapefile Layer



  1. Toggle the Editing button


  1. Click Add Polygon Feature


  1. On the Shape Digitizing Toolbar, select the tool called Rectangle From Extent


  1. Digitize rectangles around trees


  1. Save Layer Edits


  1. Toggle the Editing button to stop editing of the shapefile.

Resources

Full DeepForest documentation

Weecology DeepForest github repository