Analyzers
Last updated
Was this helpful?
Last updated
Was this helpful?
This module provides a base class (ResultAnalyzerBase
) for performing custom post-processing and
image annotation on DeGirum PySDK inference results. These analyzers can be used with
compound models, streaming gizmos, and regular models to add advanced data processing and annotation steps
to inference pipelines.
Analysis:
By overriding the analyze()
method, child classes can read and augment the
(e.g., by adding extra keys to the internal results
list).
Annotation:
By overriding the annotate()
method, child classes can draw additional overlays on the
original input image (e.g., bounding boxes, text labels, or any custom markings).
Integration:
Analyzers can be attached to a model or a compound model via the attach_analyzers()
method,
so their analysis and annotation is automatically applied to each inference result.
Create a custom analyzer subclass:
Attach it to a model or compound model:
Run inference. Each object will be passed through your analyzer, optionally modifying the result data and providing a new overlay.
ResultAnalyzerBase
Bases: ABC
Base class for result analyzers which can modify or extend the content of inference results and optionally annotate images with new data.
Subclasses should override
analyze(result)
: to augment or inspect the inference result.
annotate(result, image)
: to draw additional overlays or text onto the provided image.
__del__()
Called when the analyzer object is about to be destroyed.
Invokes finalize()
to ensure any open resources are cleaned up.
analyze(result)
abstractmethod
Analyze and optionally modify a DeGirum PySDK inference result.
This method should access and potentially modify result.results
(the list of detections,
classifications, or similar structures) to add any custom fields. These modifications
will then appear in downstream processes or when the result is displayed/serialized.
Parameters:
result
The inference result object to analyze. Subclasses can read and/or modify the internal results
list or other properties.
required
analyze_and_annotate(result, image)
Helper method to perform both analysis and annotation in one step.
Calls self.analyze(result)
.
Calls self.annotate(result, image)
.
Parameters:
result
The inference result object to process.
required
image
ndarray
The image to annotate.
required
Returns:
ndarray
numpy.ndarray: The annotated image after analysis.
finalize()
Perform any finalization or cleanup actions before the analyzer is discarded.
This can be useful for analyzers that accumulate state (e.g., for multi-frame analysis). By default, this does nothing.
image_overlay_substitute(result, analyzers)
Substitute the image_overlay
property of the given inference result
object
so that future calls to result.image_overlay
automatically apply the analyzers'annotate()
methods.
This method creates a new class that inherits from the original result class and
overrides the image_overlay
property. The new class does the following:
Calls the base class's image_overlay
property to get the image annotated by original result class.
Applies each analyzer's annotate()
method to the image, in order.
Parameters:
result
The inference result whose image_overlay
property will be replaced.
required
analyzers
A list of analyzer objects to apply for annotation.
required
clone_result(result)
Create a shallow clone of a DeGirum PySDK inference result object, duplicating the internal inference results list but reusing references to the original image.
This is useful when you want to create a separate copy of the result for further modifications without altering the original.
Parameters:
result
The inference result object to clone.
required
Returns:
A cloned result object with result._inference_results
deep-copied.
List[]