inference
wherobots.inference
Public API for wherobots.inference.
ModelMetadata
dataclass
Loads and parses Machine Learning Model Metadata JSON.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_meta_path
|
str
|
Path or S3 URI to the model metadata JSON file. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
Shape mismatch error if the length of the class_map differs from the shape of the result. |
ValueError
|
Only MLM metadata that define statistics per band and norm_by_channels are supported. |
read_model_metadata(model_meta_uri)
Reads and parses a model metadata JSON file from S3.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_meta_uri
|
str
|
The S3 URI for the model metadata JSON file. |
required |
Returns:
Type | Description |
---|---|
STACObject
|
pystac.STACObject: The parsed model metadata conforming to the MLM Extension. |
create_object_detection_udfs(batch_size, sedona)
Create and register UDFs for object detection tasks.
Registers SQL functions for RS_DETECT_BBOXES and RS_FILTER_BOX_CONFIDENCE and returns corresponding functions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch_size
|
int
|
The number of samples to include in each batch. |
required |
sedona
|
SedonaContext
|
The current Sedona context. |
required |
Returns:
Type | Description |
---|---|
tuple[Callable, Callable]
|
Tuple[Callable, Callable]: A tuple of functions configured for object detection. |
create_semantic_segmentation_udfs(batch_size, sedona)
Create and register SQL functions for semantic segmentation tasks.
Registers SQL function as RS_SEGMENT and returns a corresponding function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch_size
|
int
|
The number of samples to include in each batch. |
required |
sedona
|
SedonaContext
|
The current Sedona context. |
required |
Returns:
Name | Type | Description |
---|---|---|
Callable |
Callable
|
A function configured for semantic segmentation. |
create_single_label_classification_udfs(batch_size, sedona)
Create and register SQL Functions for single-label classification tasks.
Registers SQL function as RS_CLASSIFY RS_MAX_CONFIDENCE and returns corresponding functions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch_size
|
int
|
The number of samples to include in each batch. |
required |
sedona
|
SedonaContext
|
The current Sedona context. |
required |
Returns:
Type | Description |
---|---|
Callable
|
Tuple[Callable, Callable]: A tuple of pandas UDFs configured for single-label |
Callable
|
classification tasks, [RS_CLASSIFY, RS_MAX_CONFIDENCE]. |
show_detections(df, geometry_column=None, geometry_crs='EPSG:4326', confidence_threshold=0.05, plot_geoms=True, side_by_side=True)
Plot raster images with detected object geometries overlaid.
This function handles both Pandas and Wherobots DataFrames containing geometries, automatically detecting the raster column. It is compatible with dataframes returned from a SQL inference function. Exploded dataframes are not supported.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame | DataFrame
|
Pandas or Wherobots DataFrame containing raster data and detection results |
required |
geometry_column
|
str
|
Column name containing WKT geometries (if None, automatically detected) |
None
|
geometry_crs
|
str
|
Coordinate reference system of the geometries (default: EPSG:4326) |
'EPSG:4326'
|
confidence_threshold
|
float
|
Minimum confidence score for displaying detections |
0.05
|
plot_geoms
|
bool
|
Whether to overlay geometries on the images |
True
|
side_by_side
|
bool
|
Whether to show original and detection images side by side |
True
|
Raises:
Type | Description |
---|---|
ValueError
|
If the DataFrame is empty or required columns cannot be found |