You may want to check the accuracy of an Object Detection model by its precision/recall metrics at the image level. A custom post-processing that convert the object detection output to classification values can help you summarize if the image detected any object.
from landinglens.model_iteration.sdk import BaseTransform, DataItem
class ObjectDetectionToClassification(BaseTransform): """Transforms a object detection output into a classification output.""" def__init__(self, boxes_threshold: int = 1, **params): """ Parameters ---------- """ assert isinstance( boxes_threshold, int ), f"Score position is not an integer. Got {boxes_threshold}" assert ( boxes_threshold > 0 ), f"Score position is not positive. Got {boxes_threshold}" self.boxes_threshold = boxes_threshold
def__call__(self, inputs: DataItem) -> DataItem: """Return a new DataItem with transformed attributes. DataItem has following attributes: image - input image. label, score - input label and its score. mask_scores, mask_labels - segmentation mask probabilities and classes. bboxes, bboxes_labels, bboxes_scores - object detection bounding boxes. user_data - any additional data that you want to store for subsequent transform.
Returns ------- A named tuple class DataItem with the modified attributes. """ bboxes = inputs.bboxes
if bboxes isNone: return DataItem(image=inputs.image, label=0)
if bboxes.shape[0] >= self.boxes_threshold: label = 1#ng else: label = 0 # ok