You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Clone the [Weecology staged recipes](https://github.com/weecology/staged-recipes).
114
+
Clone the [Weecology staged recipes](https://github.com/weecology/staged-recipes).
115
115
Checkout the deepforest branch, update the `deepforest/meta.yaml` with the new version and the sha256 values. Sha256 values are obtained from the source on [PYPI download files](https://pypi.org/project/deepforest/#files) using the deepforest-{version-number}.tar.gz.
Copy file name to clipboardExpand all lines: docs/user_guide/03_cropmodels.md
+222-1Lines changed: 222 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ Why would you want to apply a model directly to each crop? Why not train a multi
14
14
15
15
While that approach is certainly valid, there are a few key benefits to using CropModels, especially in common use cases:
16
16
17
-
-**Flexible Labeling**: Object detection models require that all objects of a particular class be annotated within an image, which can be impossible for detailed category labels. For example, you might have bounding boxes for all ‘trees’ in an image, but only have species or health labels for a small portion of them based on ground surveys. Training a multi-class object detection model would mean training on only a portion of your available data.
17
+
-**Flexible Labeling**: Object detection models require that all objects of a particular class be annotated within an image, which can be impossible for detailed category labels. For example, you might have bounding boxes for all 'trees' in an image, but only have species or health labels for a small portion of them based on ground surveys. Training a multi-class object detection model would mean training on only a portion of your available data.
18
18
-**Simpler and Extendable**: CropModels decouple detection and classification workflows, allowing separate handling of challenges like class imbalance and incomplete labels, without reducing the quality of the detections. Two-stage object detection models can be finicky with similar classes and often require expertise in managing learning rates.
19
19
-**New Data and Multi-sensor Learning**: In many applications, the data needed for detection and classification may differ. The CropModel concept provides an extendable piece that allows for advanced pipelines.
20
20
@@ -177,4 +177,225 @@ class CustomCropModel(CropModel):
177
177
178
178
# Create an instance of the custom CropModel
179
179
model = CustomCropModel()
180
+
```
181
+
182
+
## Making Predictions Outside of predict_tile
183
+
184
+
While `predict_tile` provides a convenient way to run predictions on detected objects, you can also use the CropModel directly for classification tasks. This is useful when you have pre-cropped images or want to run classification independently.
Often we have a large number of tiles we want to predict. DeepForest uses [PyTorch Lightning](https://lightning.ai/docs/pytorch/stable/) to scale inference. This gives us access to powerful tools for scaling without any changes to user code. DeepForest automatically detects whether you are running on GPU or CPU. The parallelization strategy is to run each tile on a separate GPU, we cannot parallelize crops from within the same tile across GPUs inside of main.predict_tile(). If you set m.create_trainer(accelerator="gpu", devices=4), and run predict_tile, you will only use 1 GPU per tile. This is because we need access to all crops to create a mosiac of the predictions.
37
+
Often we have a large number of tiles we want to predict. DeepForest uses [PyTorch Lightning](https://lightning.ai/docs/pytorch/stable/) to scale inference. This gives us access to powerful tools for scaling without any changes to user code. DeepForest automatically detects whether you are running on GPU or CPU.
38
38
39
-
### Scaling prediction across multiple GPUs
39
+
There are three dataset strategies that *balance cpu memory, gpu memory, and gpu utilization* using batch sizes.
40
40
41
-
There are a few situations in which it is useful to replicate the DeepForest module across many separate Python processes. This is especially helpful when we have a series of non-interacting tasks, often called 'embarrassingly parallel' processes. In these cases, no DeepForest instance needs to communicate with another instance. Rather than coordinating GPUs with the associated annoyance of overhead and backend errors, we can just launch separate jobs and let them finish on their own. One helpful tool in Python is [Dask](https://www.dask.org/). Dask is a wonderful open-source tool for coordinating large-scale jobs. Dask can be run locally, across multiple machines, and with an arbitrary set of resources.
The `dataloader_strategy` parameter has three options:
42
45
43
-
### Example Dask and DeepForest integration using SLURM
46
+
***single**: Loads the entire image into CPU memory and passes individual windows to GPU.
44
47
45
-
Imagine we have a list of images we want to predict using `deepforest.main.predict_tile()`. DeepForest does not allow multi-GPU inference within each tile, as it is too much of a headache to make sure the threads return the correct overlapping window. Instead, we can parallelize across tiles, such that each GPU takes a tile and performs an action. The general structure is to create a Dask client across multiple GPUs, submit each DeepForest `predict_tile()` instance, and monitor the results. In this example, we are using a SLURMCluster, a common job scheduler for large clusters. There are many similar ways to create a Dask client object that will be specific to a particular organization. The following arguments are specific to the University of Florida cluster, but will be largely similar to other SLURM naming conventions. We use the extra Dask package, `dask-jobqueue`, which helps format the call.
48
+
***batch**: Loads the entire image into GPU memory and creates views of the image as batches. Requires the entire tile to fit into GPU memory. CPU parallelization is possible for loading images.
46
49
50
+
***window**: Loads only the desired window of the image from the raster dataset. Most memory efficient option, but cannot parallelize across windows due to Python's Global Interpreter Lock, workers must be set to 0.
47
51
48
-
```python
49
-
from dask_jobqueue import SLURMCluster
50
-
from dask.distributed import Client
51
-
52
-
cluster = SLURMCluster(processes=1,
53
-
cores=10,
54
-
memory="40 GB",
55
-
walltime='24:00:00',
56
-
job_extra=extra_args,
57
-
extra=['--resources gpu=1'],
58
-
nanny=False,
59
-
scheduler_options={"dashboard_address": ":8787"},
60
-
local_directory="/orange/idtrees-collab/tmp/",
61
-
death_timeout=100)
62
-
print(cluster.job_script())
63
-
cluster.scale(10)
64
-
65
-
dask_client = Client(cluster)
66
-
```
52
+
## Data Loading
67
53
68
-
This job script gets a single GPUs with "40GB" of memory with 10 cpus. We then ask for 10 instances of this setup.
69
-
Now that we have a dask client, we can send our custom function.
54
+
DeepForest uses PyTorch's DataLoader for efficient data loading. One important parameter for scaling is the number of CPU workers, which controls parallel data loading using multiple CPU processes. This can be set
70
55
71
-
```python
72
-
import os
73
-
from deepforest import main
74
-
75
-
deffunction_to_parallelize(tile):
76
-
m = main.deepforest()
77
-
m.load_model("weecology/deepforest-tree") # sub in the custom logic to load your own models
0 workers runs without multiprocessing, workers > 1 runs with multiprocessing. Increase this value slowly, as IO constraints can lead to deadlocks among workers.
94
60
95
-
We can wait to see the futures as they complete! Dask also has a beautiful visualization tool using bokeh.
0 commit comments