Postprocessor Module
Last updated
Was this helpful?
Last updated
Was this helpful?
degirum.postprocessor.ClassificationResults
Bases: InferenceResults
InferenceResult class implementation for classification results type
degirum.postprocessor.ClassificationResults.image_overlay
property
Image with AI inference results drawn. Image type is defined by the selected graphical backend. Each time this property is accessed, new overlay image object is created and all overlay details are redrawn according to the current settings of overlay_*** properties.
degirum.postprocessor.ClassificationResults.overlay_show_labels_below
property
writable
Specifies if overlay labels should be drawn below the image or on image itself
degirum.postprocessor.ClassificationResults.__str__()
Convert inference results to string
degirum.postprocessor.DetectionResults
Bases: InferenceResults
InferenceResult class implementation for detection results type
degirum.postprocessor.DetectionResults.image_overlay
property
Image with AI inference results drawn. Image type is defined by the selected graphical backend.
degirum.postprocessor.DetectionResults.__str__()
Convert inference results to string
degirum.postprocessor.DetectionResults._resize_mask(mask)
Return image segmentation mask scaled with respect to the provided image transformation callback
conversion
: coordinate conversion function accepting two arguments (x,y) and returning two-element tuple
overlay_data
: overlay data to blend on top of input image
original_width
: original image width
original_height
: original image height
degirum.postprocessor.DetectionResults._run_length_decode(rle)
Returns NumPy array for run length encoded string, reshaped to specified shape
Parameters:
rle
dict
RLE image segmentation mask dictionary
required
Returns:
results
NumPy array
NumPy array, representing an image segmentation mask.
degirum.postprocessor.DetectionResults.generate_overlay_color(model_params, label_dict)
staticmethod
Overlay colors generator.
Returns:
list
general overlay color data for segmentation results
degirum.postprocessor.Hand_DetectionResults
Bases: InferenceResults
InferenceResult class implementation for pose detection results type
degirum.postprocessor.Hand_DetectionResults.image_overlay
property
Image with AI inference results drawn. Image type is defined by the selected graphical backend.
degirum.postprocessor.Hand_DetectionResults.__str__()
Convert inference results to string
degirum.postprocessor.InferenceResults
Inference results container class.
This class is a base class for a set of classes designed to handle inference results of particular model types such as classification, detection etc.
Note
You never construct model objects yourself. Objects of those classes are returned by various predict methods of degirum.model.Model class.
degirum.postprocessor.InferenceResults.image
property
Original image.
Returned image object type is defined by the selected graphical backend (see degirum.model.Model.image_backend).
degirum.postprocessor.InferenceResults.image_model
property
Model input image data: image converted to AI model input specifications.
Image type is raw binary array.
degirum.postprocessor.InferenceResults.image_overlay
property
Image with AI inference results drawn on a top of original image.
Drawing details depend on the inference result type:
For classification models the list of class labels with probabilities is printed below the original image.
For object detection models bounding boxes of detected object are drawn on the original image.
For pose detection models detected keypoints and keypoint connections are drawn on the original image.
For segmentation models detected segments are drawn on the original image.
Returned image object type is defined by the selected graphical backend (see degirum.model.Model.image_backend).
degirum.postprocessor.InferenceResults.info
property
Input data frame information object.
degirum.postprocessor.InferenceResults.overlay_alpha
property
writable
Alpha-blend weight for overlay details.
degirum.postprocessor.InferenceResults.overlay_blur
property
writable
Overlay blur option. None for no blur, "all" to blur all objects, a class label or list of class labels to blur specific objects.
degirum.postprocessor.InferenceResults.overlay_color
property
writable
Color for inference results drawing on overlay image.
3-element RGB tuple or list of 3-element RGB tuples.
degirum.postprocessor.InferenceResults.overlay_fill_color
property
writable
Image fill color in case of image padding.
3-element RGB tuple.
degirum.postprocessor.InferenceResults.overlay_font_scale
property
writable
Font scale to use for overlay text.
degirum.postprocessor.InferenceResults.overlay_line_width
property
writable
Line width in pixels for inference results drawing on overlay image.
degirum.postprocessor.InferenceResults.overlay_show_labels
property
writable
Specifies if class labels should be drawn on overlay image.
degirum.postprocessor.InferenceResults.overlay_show_probabilities
property
writable
Specifies if class probabilities should be drawn on overlay image.
degirum.postprocessor.InferenceResults.results
property
Inference results list.
Each element of the list is a dictionary containing information about one inference result. The dictionary contents depends on the AI model.
For classification models each inference result dictionary contains the following keys:
category_id
: class numeric ID.
label
: class label string.
score
: class probability.
Example
For multi-label classification models each inference result dictionary contains the following keys:
classifier
: object class string.
results
: list of class labels and its scores. Scores are optional.
The results
list element is a dictionary with the following keys:
label
: class label string.
score
: optional class label probability.
Example
For object detection models each inference result dictionary may contain the following keys:
category_id
: detected object class numeric ID.
label
: detected object class label string.
score
: detected object probability.
bbox
: detected object bounding box list [xtop, ytop, xbot, ybot]
.
landmarks
: optional list of keypoints or landmarks. It is the list of dictionaries, one per each keypoint/landmark.
mask
: optinal dictionary of run-length encoded (RLE) object segmentation mask array representation.
angle
: optional angle (in radians) for rotating bounding box around its center. This is used in the case of oriented bounding boxes.
The landmarks
list is defined for special cases like pose detection of face points detection results. Each landmarks
list element is a dictionary with the following keys:
category_id
: keypoint numeric ID.
label
: keypoint label string.
score
: keypoint detection probability.
landmark
: keypoint coordinate list [x,y]
.
connect
: optional list of IDs of connected keypoints.
The mask
dictionary is defined for the special case of object segmentation results, with the following keys:
x_min
: x-coordinate in the model input image at which the top-left corner of the box enclosing this mask should be placed.
y_min
: y-coordinate in the model input image at which the top-left corner of the box enclosing this mask should be placed.
height
: height of segmentation mask array
width
: width of segmentation mask array
data
: string representation of a buffer of unsigned 32-bit integers carrying the RLE segmentation mask array.
The object detection keys (bbox
, score
, label
, and category_id
) must be either all present or all absent. In the former case the result format is suitable to represent pure object detection results. In the later case, one of the following keys must be present:
the landmarks
key
the mask
key
The following statements are then true:
If the landmarks
key is present, the result format is suitable to represent pure landmark detection results, such as pose detection.
If the mask
key is present, the result format is suitable to represent pure segmentation results. If, optionally, the category_id
key is also present, the result format is suitable to represent semantic segmentation results.
When both object detection keys and the landmarks
key are present, the result format is suitable to represent mixed model results, when the model detects not only object bounding boxes, but also keypoints/landmarks within the bounding box.
When both object detection keys and the mask
key are present, the result format is suitable to represent mixed model results, when the model detects not only object bounding boxes, but also segmentation masks within the bounding box (i.e. instance segmentation).
Example of pure object detection results:
Example
Example of oriented object detection results:
Example
Example of landmark object detection results:
Example
Example of segmented object detection results:
Example
For hand palm detection models each inference result dictionary contains the following keys:
score
: probability of detected hand.
handedness
: probability of right hand.
landmarks
: list of dictionaries, one per each hand keypoint.
Each landmarks
list element is a dictionary with the following keys:
label
: classified object class label.
category_id
: classified object class index.
landmark
: landmark point coordinate list [x, y, z]
.
world_landmark
: metric world landmark point coordinate list [x, y, z]
.
connect
: list of adjacent landmarks indexes.
Example
For segmentation models inference result is a single-element list. That single element is a dictionary, containing single key data
. The value of this key is 2D numpy array of integers, where each integer value represents a class ID of the corresponding pixel. The class IDs are defined by the model label dictionary.
Example
degirum.postprocessor.InferenceResults.type
property
Inference result type: one of
"classification"
"detection"
"pose detection"
"segmentation"
degirum.postprocessor.InferenceResults.__init__(*, model_params, input_image=None, model_image=None, inference_results, draw_color=(255, 255, 128), line_width=3, show_labels=True, show_probabilities=False, alpha='auto', font_scale=1.0, fill_color=(0, 0, 0), blur=None, frame_info=None, conversion, label_dictionary={})
Constructor.
Note
You never construct InferenceResults
objects yourself – the ancestors of this class are returned as results of AI inferences from degirum.model.Model.predict, degirum.model.Model.predict_batch, and degirum.model.Model.predict_dir methods.
Parameters:
model_params
ModelParams
Model parameters object as returned by degirum.model.Model.model_info.
required
input_image
any
Original input data.
None
model_image
any
Input data converted per AI model input specifications.
None
inference_results
list
Inference results data.
required
draw_color
tuple
Color for inference results drawing on overlay image.
(255, 255, 128)
line_width
int
Line width in pixels for inference results drawing on overlay image.
3
show_labels
bool
True to draw class labels on overlay image.
True
show_probabilities
bool
True to draw class probabilities on overlay image.
False
alpha
Union[float, str]
Alpha-blend weight for overlay details.
'auto'
font_scale
float
Font scale to use for overlay text.
1.0
fill_color
tuple
RGB color tuple to use for filling if any form of padding is used.
(0, 0, 0)
blur
Union[str, list, None]
Optional blur parameter to apply to the overlay image. If None, no blur is applied. If "all" all objects are blurred. If a class label or a list of class labels is provided, only objects with those labels are blurred.
None
frame_info
any
Input data frame information object.
None
conversion
Callable
Coordinate conversion function accepting two arguments (x,y)
and returning two-element tuple. This function should convert model-based coordinates to input image coordinates.
required
label_dictionary
dict[str, str]
Model label dictionary.
{}
degirum.postprocessor.InferenceResults.__str__()
Conversion to string
degirum.postprocessor.InferenceResults.generate_colors()
staticmethod
Generate a list of unique RGB color tuples.
degirum.postprocessor.InferenceResults.generate_overlay_color(model_params, label_dict)
staticmethod
Overlay colors generator.
Parameters:
model_params
ModelParams
Model parameters.
required
label_dict
dict
Model labels dictionary.
required
Returns:
Union[list, tuple]
Overlay color tuple or list of tuples.
degirum.postprocessor.MultiLabelClassificationResults
Bases: InferenceResults
InferenceResult class implementation for multi-label classification results type
degirum.postprocessor.MultiLabelClassificationResults.image_overlay
property
Image with AI inference results drawn. Image type is defined by the selected graphical backend. Each time this property is accessed, new overlay image object is created and all overlay details are redrawn according to the current settings of overlay_*** properties.
degirum.postprocessor.MultiLabelClassificationResults.overlay_show_labels_below
property
writable
Specifies if overlay labels should be drawn below the image or on image itself
degirum.postprocessor.MultiLabelClassificationResults.__str__()
Convert inference results to string
degirum.postprocessor.SegmentationResults
Bases: InferenceResults
InferenceResult class implementation for segmentation results type
degirum.postprocessor.SegmentationResults.image_overlay
property
Image with AI inference results drawn. Image type is defined by the selected graphical backend.
degirum.postprocessor.SegmentationResults.__str__()
Convert inference results to string
degirum.postprocessor.SegmentationResults.generate_overlay_color(model_params, label_dict)
staticmethod
Overlay colors generator.
Returns:
list
general overlay color data for segmentation results
degirum.postprocessor._ListFlowTrue
Bases: list
list subclass to specify custom yaml style
degirum.postprocessor._create_overlay_color_dataset(model_params, label_dict)
Create and return default color data based on postprocessor type.
Parameters:
model_params
ModelParams
Model parameters.
required
label_dict
dict[str, str]
Model labels dictionary.
required
Returns:
result
`list[tuple]
tuple`
degirum.postprocessor._format_num(number, precision=2)
Return formatted number based on type of numeric value
degirum.postprocessor._inference_result_type(model_params)
Create and return inference result builder function based on model parameters
Parameters:
model_params
: model parameters
Returns inference result builder function
degirum.postprocessor.create_postprocessor(*args, **kwargs)
Create and return postprocessor object.
For the list of arguments see documentation for constructor of degirum.postprocessor.InferenceResults class.
Returns:
InferenceResults instance corresponding to model results type.
This API Reference is based on PySDK 0.15.2.