DeepForest modal app#
Modal app for serverless DeepForest [1] inference, training/fine tuning of tree crown detection and species classification models.
Features#
Execute all your pipeline (preprocessing, training/fine tuning, inference, postprocessing…) within the same local script/notebook:
When running DeepForest inference and training/fine tuning of tree detection models, this library will handle setting up a Modal ephemeral apps in a GPU-enabled environment, execute the deep learning parts there and you will then retrieve the results (e.g., a geopandas data frame) as a local variable within your notebook
Optimized defaults for the serverless infrastructure (i.e., different training and inference GPUs) and matching settings (batch sizes, number of workers, image pre-loading…) to improve performance. TODO: support for multi-GPU training coming shortly.
The required data (e.g., aerial imagery) and model checkpoints are uploaded to persistent Modal storage volumes
Model checkpoints from HuggingFace Hub and PyTorch Hub are cached locally in a storage volume so uptime for ephemeral apps is minimal
Example annotations from the TreeAI Database (left), predictions with the DeepForest pre-trained tree crown model (center) and with the fine-tuned model (right).
Examples#
The following example notebooks use the TreeAI Database [2] to illustrate the features of this setup:
getting-started.ipynb: example notebook showcasing inference and training/fine-tuning (with the default settings).advanced-customizations.ipynb: shows how to use data augmentations, logging, callbacks and sharing checkpoints in HuggingFace Hub.crop-model.ipynb: draft on multi-species classification using the DeepForest crop model.
Installation#
This app requires geopandas in the local environment, which cannot be installed with pip. Until we have a working conda-forge recipe, the easiest solution is to first install geopandas using conda/mamba, e.g.:
conda install geopandas
and then install “deepforest-modal-app” using pip:
pip install deepforest-modal-app
Acknowledgements#
A big thank you to Charles Frye and Thomas Capelle for helping me to get started with Modal.
This package was created with the martibosch/cookiecutter-geopy-package project template.
References#
Weinstein, B. G., Marconi, S., Aubry‐Kientz, M., Vincent, G., Senyondo, H., & White, E. P. (2020). DeepForest: A Python package for RGB deep learning tree crown delineation. Methods in Ecology and Evolution, 11(12), 1743-1751.
Beloiu Schwenke, M., Xia, Z., Novoselova, I., Gessler, A., Kattenborn, T., Mosig, C., Puliti, S., Waser, L., Rehush, N., Cheng, Y., Xinliang, L., Griess, V. C., & Mokroš, M. (2025). TreeAI Global Initiative - Advancing tree species identification from aerial images with deep learning (TreeAI.V1.2) [Data set]. Zenodo. https://doi.org/10.5281/zenodo.15351054