Experimental Detection¶
Use obia.detection to train a RetinaNet model that locates objects with bounding
boxes. This is an experimental workflow, separate from segmenting and classifying
polygon objects; its interfaces may change.
Install detection dependencies¶
Install the detection extra:
1 | |
The detection extra includes PyTorch, Torchvision, Albumentations, and Matplotlib.
Prepare image chips and annotations¶
TreeDetectionDataset reads raster chips and JSON annotations:
1 2 3 4 5 | |
The JSON file maps image IDs to filenames, boxes, and class labels. Box
coordinates are [xmin, ymin, xmax, ymax] in pixels. For example:
1 2 3 4 5 6 7 | |
Build a model¶
1 2 3 4 5 6 | |
Set in_channels to match the number of raster bands used for detection.
Train¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | |
Use device="cuda" for a supported NVIDIA GPU, or device="mps" for a supported
Apple Silicon installation. The CPU example works without GPU support.
Predict¶
1 2 3 4 5 6 7 8 | |
The result contains boxes, scores, and labels arrays. Boxes use pixel
coordinates; convert them with the source raster's transform if you need map
coordinates.