landingai.postprocess
class_counts(predictions)
Compute the distribution of the occurrences of each class.
Returns
A map with the predicted class/label index as the key, and a tuple of (the number of occurrence, class/label name) as the value.
Source code in landingai/postprocess.py
class_map(predictions)
Return a map from the predicted class/label index to the class/label name.
class_pixel_coverage(predictions, coverage_type='relative')
Compute the pixel coverage of each class.
Supported prediction types are: - SegmentationPrediction - ObjectDetectionPrediction
It supports two ways to compute the coverage: - "absolute" - "relative" See the documentation of the coverage_type for more details.
Parameters
predictions: a list of predictions. It could come from one or multiple images. coverage_type: "absolute" or "relative". - Absolute: The number of pixels of each predicted class. - Relative: The percentage of pixels that are predicted as the class over the sum total number of pixels of every mask. The only project type that supports "relative" is "SegmentationPrediction".
Returns
A map with the predicted class/label index as the key, and a tuple of (the coverage, class/label name) as the value.
Source code in landingai/postprocess.py
crop(predictions, image)
Crop the image based on the bounding boxes in the predictions.
NOTE: Currently, only ObjectDetectionPrediction is supported. If other types of predictions are passed in, a ValueError will be raised.
Parameters
predictions: a list of ObjectDetectionPrediction, each of which will be used to crop the image. image: the input image to be cropped from.
Returns
A list of cropped images.
Source code in landingai/postprocess.py
rescale_bboxes(predictions, scale_factor)
Rescale the bounding boxes of each ObjectDetectionPrediction in a list based on the scale factor. NOTE: this operation is NOT in-place. The input predictions will remain the same.
Parameters
predictions: a list of ObjectDetectionPrediction to be rescaled. scale_factor: the scale factor that will be applied to the predictions. The scale factors are (height, width) if it's a tuple.
Returns
A list of ObjectDetectionPrediction where the bboxes has been rescaled.
Source code in landingai/postprocess.py
rescale_bboxes_by_image_size(predictions, from_image, to_image)
Rescale the bounding boxes of each ObjectDetectionPrediction in a list based on the size of the reference images. NOTE: this operation is NOT in-place. The input predictions will remain the same.
Parameters
predictions: a list of ObjectDetectionPrediction to be rescaled. from_image: the image that serves the denominator of the scale factor. The input bboxes is at the same scale of this image. to_image: the image that serves the numerator of the scale factor. The ouput bboxes will be at the same scale of this image.
Returns
A list of ObjectDetectionPrediction where the bboxes has been rescaled.
Source code in landingai/postprocess.py
segmentation_class_pixel_coverage(predictions, coverage_type='relative')
Compute the pixel coverage of each class. The coverage is defined as the percentage of pixels that are predicted as the class over the sum total number of pixels of every mask. If the predictions are from multiple images, the coverage is the average coverage across all images.
Parameters
predictions: A list of segmentation predictions. It could come from one or multiple images.
Returns
A map with the predicted class/label index as the key, and a tuple of (the coverage percentage, class/label name) as the value. Note: The sum of the coverage percentage over all classes is not guaranteed to be 1.