Skip to content

multichannelinstancefinder

multichannelinstancefinder

Module for the multichannel instance finder

Classes

MultiChannelInstanceFinder

MultiChannelInstanceFinder(
    key="multichannelinstancefinder",
    min_area=10,
    max_area=2000000,
    threshold=0.5,
)

Bases: InstanceFinder

Instance finder for SemSeg predictions with more than one channel (classes).

Source code in niceml/mlcomponents/resultanalyzers/instancefinders/multichannelinstancefinder.py
def __init__(
    self,
    key: str = "multichannelinstancefinder",
    min_area: int = 10,
    max_area: int = 2000000,
    threshold: float = 0.5,
):
    super().__init__(
        key=key,
        min_area=min_area,
        max_area=max_area,
        threshold=threshold,
    )
Functions
analyse_datapoint
analyse_datapoint(
    data_key,
    data_predicted,
    data_loaded=None,
    additional_data=None,
    dyn_threshold=None,
    **kwargs
)

extract information about multiple predicted errors (instances) from multichannel image. The dynamic threshold can be used to override the threshold

Source code in niceml/mlcomponents/resultanalyzers/instancefinders/multichannelinstancefinder.py
def analyse_datapoint(
    self,
    data_key: str,
    data_predicted: SemSegPredictionContainer,
    data_loaded: Optional[DataInfo] = None,
    additional_data: Optional[dict] = None,
    dyn_threshold: Optional[float] = None,
    **kwargs,
) -> Optional[Any]:
    """extract information about multiple predicted errors
    (instances) from multichannel image.
    The dynamic threshold can be used to override the threshold"""

    dyn_threshold = dyn_threshold or self.threshold
    binarize_multichannel_images, _ = binarize_multichannel_image(
        image_index=data_predicted.max_prediction_idxes,
        image_scores=data_predicted.max_prediction_values,
        threshold=dyn_threshold,
    )
    mask_instances: List[MaskInstance] = []

    for class_idx, curr_binary_img in binarize_multichannel_images.items():
        instance_contours = find_contours_in_binary_image(
            binary_image=curr_binary_img.astype(np.uint8),
            min_area=self.min_area,
            max_area=self.max_area,
        )
        instance_contours = [
            InstanceContour(
                contour=error_contour,
                class_idx=int(float(class_idx)),
            )
            for error_contour in instance_contours
        ]
        mask_instance = MaskInstance(
            mask=curr_binary_img,
            instance_contours=instance_contours,
            instance_class_idx=int(float(class_idx)),
        )
        mask_instances.append(mask_instance)

    return mask_instances
get_final_metric
get_final_metric()

returns empty dict

Source code in niceml/mlcomponents/resultanalyzers/instancefinders/multichannelinstancefinder.py
def get_final_metric(self) -> Optional[dict]:
    """returns empty dict"""
    return {}

Functions