Detect and Segment Tree Crowns from Satellite Imagery Using QGIS
Detecting individual tree crowns from satellite or aerial imagery is useful for forest inventory, urban canopy monitoring, and ecological research. The DeepForest Python package provides pre-trained models that can detect trees, birds, and other objects directly from imagery. I have integrated DeepForest into the GeoAI QGIS plugin, so you can now run tree crown detection with a few clicks inside QGIS without writing any Python code.
In this tutorial, I walk through the full workflow: setting up the environment with Pixi, installing the plugin, loading sample data, running tree detection, and exporting results in multiple formats.
Video tutorial: Detect and Segment Tree Crowns with the GeoAI QGIS Plugin
What You Will Need¶
Pixi package manager (used to create an isolated Python environment for QGIS)
A GPU with CUDA support is recommended for fast inference. The plugin also works on CPU, but it will be significantly slower.
An internet connection to download the pre-trained model from Hugging Face on first use.
Set Up the Environment with Pixi¶
The GeoAI plugin requires specific versions of PyTorch, CUDA, and other deep learning libraries. Using Pixi ensures these dependencies do not conflict with your existing QGIS installation. Do not use your system QGIS for this workflow.
Create a Pixi project¶
Open a terminal and create a new Pixi project:
pixi init geo
cd geoThis creates a geo directory with a pixi.toml configuration file inside.
Configure CUDA dependencies¶
Check your CUDA version by running:
nvidia-smiLook for the CUDA version in the output (e.g., 12.x or 13.x). Then open the pixi.toml file and paste the appropriate dependency block from the GeoAI plugin installation instructions. Save the file.
Install the base environment¶
pixi installThis installs QGIS, PyTorch, and all required dependencies into the isolated Pixi environment. It may take 5 to 10 minutes depending on your internet speed.
Verify PyTorch and CUDA¶
You can verify that PyTorch and CUDA are working correctly by running the verification command from the installation instructions. The output should show your PyTorch version and confirm that CUDA and your GPU are available.
Install DeepForest¶
Due to dependency conflicts between DeepForest and some of its transitive dependencies (NumPy and Transformers version mismatches), DeepForest needs to be installed separately with pip rather than through Pixi:
pixi run pip install deepforestAfter installing DeepForest, upgrade NumPy and Transformers back to their compatible versions:
pixi run pip install --upgrade "numpy>=2.0" "transformers>=4.0"You may see some dependency warnings, but these can be safely ignored.
Install the GeoAI Plugin¶
Launch QGIS through Pixi:
pixi run qgisThen install the GeoAI plugin from the QGIS Plugin Manager:
Go to Plugins > Manage and Install Plugins.
Search for geoai.
Click Install Plugin.
After installation, the GeoAI menu appears in the menu bar and a tree icon appears in the toolbar. If you had a previous version installed, click GeoAI > Check for Updates to get the latest version, then restart QGIS.
Load Sample Data¶
DeepForest ships with built-in sample data you can use for testing. Navigate to the DeepForest package directory inside your Pixi environment:
geo/.pixi/envs/default/lib/python3.12/site-packages/deepforest/data/Inside the data folder, you will find sample GeoTIFF files. Drag the sample file (e.g., OSBS_029.tif) into the QGIS map canvas to load it.
If you already have your own satellite or aerial imagery, you can use that instead.
Run Tree Crown Detection¶
Click the tree icon in the toolbar to open the DeepForest panel.
Under Model, select deepforest-tree (the default tree segmentation model). Other models are available for detecting birds and livestock.
Click Load Model. The plugin downloads the model from Hugging Face (first time only) and loads it onto your GPU. A green confirmation message appears when the model is ready.
Select your image layer from the dropdown. If you added the layer after opening the panel, click Refresh to update the list.
Click Set Image from Layer to set the input image.
Under Predict, select Single Image mode for small images or Large Image mode for bigger GeoTIFFs that benefit from tiled processing.
Adjust the Score Threshold (default: 0.5). A higher threshold produces fewer but more confident detections. A lower threshold captures more trees but may include false positives.
Click Run Prediction.
The prediction typically completes in a few seconds for small images. The detected tree crowns appear as bounding box polygons on the map.
Export Results¶
The plugin supports multiple output formats:
Vector (GeoPackage, GeoJSON, Shapefile): Each detected tree is a polygon with attributes including bounding box coordinates, label, and confidence score. By default, results are added as a temporary layer. Right-click the layer in the Layers panel and choose Export > Save Features As to save permanently.
Raster (GeoTIFF): Each detected tree gets a unique integer ID. Select GeoTIFF in the output format dropdown and click Save Result.
Inspect Detection Results¶
Open the attribute table of the vector layer to see each detection’s properties:
label: The detected object class (e.g., “Tree”)
score: Confidence score from 0 to 1
xmin, ymin, xmax, ymax: Bounding box coordinates
You can sort by score to identify low-confidence detections and filter them out. This is useful for cleaning up results before downstream analysis.
Export Training Data¶
If the pre-trained model does not perform well enough on your specific imagery, you can fine-tune it with your own training data. The plugin makes it easy to export detection results as training datasets:
Go to the Export section in the DeepForest panel.
Select a format (e.g., COCO).
Choose an output directory and click Export.
The exported dataset includes image chips and annotation files that you can use to train or fine-tune a DeepForest model for your study area.
Tips for Better Results¶
Edge artifacts: Trees near the edges of the image may be partially detected or missed. Use imagery with sufficient overlap if you are covering a large area.
Shadows: The model can generally distinguish tree shadows from actual tree crowns, but dense shadow areas may affect results.
Large images: Switch to Large Image mode and use tiled processing with configurable patch size and overlap for better performance on large GeoTIFFs.
Refining boundaries: If you need precise tree crown boundaries rather than bounding boxes, you can pass the DeepForest output as input prompts to the Segment Anything Model (SAM) tool within the same plugin.
Resources¶
GeoAI QGIS Plugin: opengeoai
.org /qgis _plugin DeepForest: github
.com /weecology /DeepForest GeoAI GitHub: github
.com /opengeos /geoai
DeepForest’s pre-trained models provide a quick starting point for tree detection without requiring you to train your own model. While results may not be perfect for every type of imagery, the combination of fast detection and easy export makes it a practical tool for generating initial results or bootstrapping training data. Give it a try with your own imagery and feel free to open an issue on GitHub if you run into any problems.