Skip to content

bboxlabeling

bboxlabeling

Module for ObjDetInstanceLabel

Classes

ObjDetImageLabel

Labels of all ObjDetInstanceLabels on an image file

ObjDetInstanceLabel

Bases: InstanceLabel

Label information for one specific bounding box and its prediction score

Functions
calc_iou
calc_iou(other)

Calculates the IOU of two given ObjDetInstanceLabels bounding boxes

Parameters:

Returns:

  • float

    Calculated IOU

Source code in niceml/utilities/boundingboxes/bboxlabeling.py
def calc_iou(self, other: "ObjDetInstanceLabel") -> float:
    """
    Calculates the IOU of two given `ObjDetInstanceLabel`s bounding boxes

    Args:
        other: ObjDetInstanceLabel to calculate the IOU for

    Returns:
        Calculated IOU
    """
    return self.bounding_box.calc_iou(  # pylint: disable=no-member
        other=other.bounding_box
    )
scale_label
scale_label(scale_factor)

Scales an ObjDetInstanceLabel by a given scale_factor

Parameters:

  • scale_factor (float) –

    Factor to scale the ObjDetInstanceLabel by

Returns:

Source code in niceml/utilities/boundingboxes/bboxlabeling.py
def scale_label(self, scale_factor: float) -> "ObjDetInstanceLabel":
    """
    Scales an ObjDetInstanceLabel by a given `scale_factor`

    Args:
        scale_factor: Factor to scale the ObjDetInstanceLabel by

    Returns:
        Scaled instance of this ObjDetInstanceLabel"""
    return ObjDetInstanceLabel(
        class_name=self.class_name,
        class_index=self.class_index,
        color=self.color,
        active=self.active,
        bounding_box=self.bounding_box.scale(scale_factor),
        score=self.score,
        rotation=self.rotation,
    )
to_content_list
to_content_list()

Creates a list with the contents of the ObjDetInstanceLabel in the following order: 1. all bounding boxes (separately), 2. class name, 3. class index, 4. prediction score, 5. rotation

Source code in niceml/utilities/boundingboxes/bboxlabeling.py
def to_content_list(self) -> list:
    """
    Creates a list with the contents of the ObjDetInstanceLabel in the following order:
    1. all bounding boxes (separately),
    2. class name,
    3. class index,
    4. prediction score,
    5. rotation
    """
    content_list = list(  # pylint: disable=no-member
        self.bounding_box.get_absolute_ullr()
    )
    content_list += [self.class_name, self.class_index, self.score, self.rotation]
    return content_list

Functions

dict_to_objdet_instance_label

dict_to_objdet_instance_label(data)

Converts a list of dicts to a list of ObjDetInstanceLabels

Source code in niceml/utilities/boundingboxes/bboxlabeling.py
def dict_to_objdet_instance_label(
    data: List[Union[dict, ObjDetInstanceLabel]]
) -> List[ObjDetInstanceLabel]:
    """Converts a list of dicts to a list of ObjDetInstanceLabels"""
    converted_data: List[ObjDetInstanceLabel] = []
    for entry in data:
        if isinstance(entry, dict):
            converted_data.append(ObjDetInstanceLabel(**entry))
        else:
            converted_data.append(entry)
    return converted_data

obj_instance_factory_from_content_list

obj_instance_factory_from_content_list(content_list)

Creates an ObjDetInstanceLabel from a list of values. Correct order of 'content_list' required: idx 0-3: ullr coordinates, idx 4: class_name, idx 5: class_idx, idx 6: prediction score, idx 7: rotation

Source code in niceml/utilities/boundingboxes/bboxlabeling.py
def obj_instance_factory_from_content_list(
    content_list: list,
) -> ObjDetInstanceLabel:
    """Creates an ObjDetInstanceLabel from a list of values.
    Correct order of 'content_list' required:
    idx 0-3: ullr coordinates,
    idx 4: class_name,
    idx 5: class_idx,
    idx 6: prediction score,
    idx 7: rotation"""
    bbox = bounding_box_from_ullr(*content_list[:4])
    class_name: str = content_list[4]
    class_index: Optional[int] = content_list[5]
    score: Optional[float] = content_list[6]
    rotation: int = content_list[7]
    return ObjDetInstanceLabel(
        class_name=class_name,
        bounding_box=bbox,
        class_index=class_index,
        score=score,
        rotation=rotation,
    )