Scoutbot API
Scoutbot is the machine learning interface for the Scout project. This page specifies the Python API to interact with all of the algorithms and machine learning models that have been pretrained for inference in a production environment.
Tile Batched (v3)
Localizer (LOC)
Compatibility wrapper for ScoutBot model-store configuration and fetching.
- scoutbot.loc.export_coreml(config, force: bool = False, observer=None) str[source]
Export a Core ML
.mlpackagefrom its source.ptmodel into the cache.The source
.ptis fetched first if needed. The export is FP16 (half=True) with NMS disabled (SAHI does its own NMS) and a fixed input size equal to the config’s slice size — static shapes are an ANE requirement, and matching the slice size avoids a resize on every tile.
- scoutbot.loc.fetch(config='v3', observer=None) str[source]
Fetch the YOLOv8 model file, downloading only if absent or hash-mismatched.
Checks the local model registry first; skips all network I/O when a valid cached entry is found. Registers the model after a successful download so subsequent calls resolve offline.
- Parameters:
config (str or None) –
'v3'or'v3-cls'. Defaults to'v3'.- Returns:
local model file path.
- Return type:
- Raises:
AssertionError – If the model cannot be fetched or MD5 verification fails.
Pipeline (PIPE)
ScoutBot v3 Pipeline
ScoutBot provides a unified ML pipeline for wildlife detection in aerial imagery. The pipeline uses YOLOv8 with SAHI (Slicing Aided Hyper Inference) for detecting animals in large images.
Example usage:
import scoutbot
# Process a single image
filepath = '/path/to/image.jpg'
wic_score, detections = scoutbot.pipeline(filepath, config='v3')
# Process multiple images in batch
filepaths = ['/path/to/image1.jpg', '/path/to/image2.jpg']
wic_list, detects_list = scoutbot.batch(filepaths, config='v3')
# Each detection is a dictionary:
# {
# 'l': class_label (str)
# 'c': confidence (float)
# 'x': x_top_left (float)
# 'y': y_top_left (float)
# 'w': width (float)
# 'h': height (float)
# }
- scoutbot.__init__.batch(filepaths, config=None, model_name=None, backend_device='cuda:0', loc_thresh=0.45, slice_height=512, slice_width=512, overlap_height_ratio=0.25, overlap_width_ratio=0.25, perform_standard_pred=False, postprocess_class_agnostic=True, show_progress=True, observer=None)[source]
Run the ML pipeline on a batch of image filepaths and return detections.
The output is a list of outputs matching the output of
scoutbot.pipeline(), except the processing reuses the loaded model for efficiency.- Parameters:
filepaths (list) – list of image filepaths (relative or absolute)
config (str, optional) – the configuration to use, one of
v3orv3-cls. Defaults tov3.backend_device (str) – torch backend device (e.g., ‘cuda:0’, ‘cpu’, ‘mps’)
loc_thresh (float) – confidence threshold for detections
slice_height (int) – height of image slices for SAHI
slice_width (int) – width of image slices for SAHI
overlap_height_ratio (float) – vertical overlap ratio between slices
overlap_width_ratio (float) – horizontal overlap ratio between slices
perform_standard_pred (bool) – also run standard (non-sliced) prediction
postprocess_class_agnostic (bool) – apply class-agnostic NMS
show_progress (bool) – show progress bar during processing
- Returns:
list of wic scores, list of detection lists
- Return type:
- scoutbot.__init__.batch_resumable(filepaths, output_path, config=None, model_name=None, backend_device='cuda:0', loc_thresh=0.45, slice_height=512, slice_width=512, overlap_height_ratio=0.25, overlap_width_ratio=0.25, perform_standard_pred=False, postprocess_class_agnostic=True, show_progress=True, observer=None, processes=1, summary_json=None)[source]
Process images with automatic resume capability.
Results are written to a JSONL file as each image completes. If processing is interrupted, calling again with the same output_path will skip already-processed images.
Each line in the output JSONL file is a complete JSON object:
{"filepath": "/path/to/img.jpg", "wic": 0.85, "detections": [...], "timestamp": "...", "config": "v3"}
- Parameters:
filepaths (list) – list of image filepaths (relative or absolute)
output_path (str or Path) – path to output JSONL file
config (str, optional) – the configuration to use, one of
v3orv3-cls. Defaults tov3.backend_device (str) – torch backend device (e.g., ‘cuda:0’, ‘cpu’, ‘mps’)
loc_thresh (float) – confidence threshold for detections
slice_height (int) – height of image slices for SAHI
slice_width (int) – width of image slices for SAHI
overlap_height_ratio (float) – vertical overlap ratio between slices
overlap_width_ratio (float) – horizontal overlap ratio between slices
perform_standard_pred (bool) – also run standard (non-sliced) prediction
postprocess_class_agnostic (bool) – apply class-agnostic NMS
show_progress (bool) – show progress bar during processing
processes (int) – number of worker processes to use. Defaults to 1 (the sequential loop). When greater than 1, the model is resolved once in the parent and each of the N worker processes loads its own copy, so ensure N copies fit in available VRAM. Linux/CUDA is the primary target for this mode. On platforms without a
forkserverstart method (e.g. Windows), a value greater than 1 is not honored: a warning is logged and the sequential path runs.summary_json (str or Path, optional) – if given, the machine-readable batch summary (counts, timing, throughput) is written to this path as JSON on completion, in both sequential and multiprocess modes.
- Returns:
Summary with keys ‘processed’, ‘skipped’, ‘errors’, ‘total’
- Return type:
- scoutbot.__init__.example()[source]
Run the pipeline on the bundled example image as a quick end-to-end smoke check.
Downloads the example image (cached under the OSW home), runs
pipelinewith the defaultv3config, prints the WIC score, detection count, and detections, and returns(wic_score, detections). This is a single-image install check, not a tour of the API – see the docs for batch, multi-class (v3-cls), and Core ML usage.
- scoutbot.__init__.fetch(config=None, observer=None)[source]
Fetch the YOLOv8 model file from CDN if it does not exist locally.
- scoutbot.__init__.get_classes(config=None)[source]
Get the list of class labels supported by the model.
- scoutbot.__init__.pipeline(filepath, config=None, model_name=None, batched_detection_model=None, backend_device='cuda:0', loc_thresh=0.45, slice_height=512, slice_width=512, overlap_height_ratio=0.25, overlap_width_ratio=0.25, perform_standard_pred=False, postprocess_class_agnostic=True, observer=None)[source]
Run the ML pipeline on a given image filepath and return the detections.
The final output is a list of dictionaries, each representing a single detection. Each dictionary has a structure with the following keys:
{ 'l': class_label (str) 'c': confidence (float) 'x': x_top_left (float) 'y': y_top_left (float) 'w': width (float) 'h': height (float) }
- Parameters:
filepath (str) – image filepath (relative or absolute)
config (str, optional) – the configuration to use, one of
v3orv3-cls. Defaults tov3.batched_detection_model – Pre-loaded YOLOv8 model (optional, for batch efficiency)
backend_device (str) – torch backend device (e.g., ‘cuda:0’, ‘cpu’, ‘mps’)
loc_thresh (float) – confidence threshold for detections
slice_height (int) – height of image slices for SAHI
slice_width (int) – width of image slices for SAHI
overlap_height_ratio (float) – vertical overlap ratio between slices
overlap_width_ratio (float) – horizontal overlap ratio between slices
perform_standard_pred (bool) – also run standard (non-sliced) prediction
postprocess_class_agnostic (bool) – apply class-agnostic NMS
- Returns:
wic score (max detection confidence), list of detections
- Return type:
Utilities
Scoutbot utilities file for common and handy functions.