loki2.models.cell_segmentation.postprocessing
Postprocessing of Loki2 network output for cell detection.
This module provides CPU-based postprocessing for extracting detected cells from network prediction maps.
Module Contents
- class loki2.models.cell_segmentation.postprocessing.DetectionCellPostProcessor(nr_types: int, magnification: Literal[20, 40] = 40, gt: bool = False)
Postprocessor for extracting detected cells from prediction maps.
This class processes network prediction maps to extract detected cells using CPU-based operations.
- nr_types
- magnification
- gt
- check_network_output(predictions_: Dict[str, torch.Tensor]) None
Check if the network output is valid.
- Parameters:
predictions –
Network predictions dictionary with required keys: * nuclei_binary_map: Binary nucleus predictions. Shape: (B, H, W, 2) * nuclei_type_map: Type prediction of nuclei.
Shape: (B, H, W, self.nr_types)
hv_map: Horizontal-Vertical nuclei mapping. Shape: (B, H, W, 2)
- Raises:
AssertionError – If predictions dictionary is invalid or missing required keys.
- post_process_batch(predictions_: Dict[str, torch.Tensor]) Tuple[torch.Tensor, List[Dict[str, Any]]]
Post-process a batch of predictions and generate cell dictionaries.
- Parameters:
predictions –
Network predictions dictionary with required keys: * nuclei_binary_map: Binary nucleus predictions. Shape: (B, H, W, 2) * nuclei_type_map: Type prediction of nuclei.
Shape: (B, H, W, self.nr_types)
hv_map: Horizontal-Vertical nuclei mapping. Shape: (B, H, W, 2)
- Returns:
Instance map tensor where each instance has own integer. Shape: (B, H, W)
List of cell dictionaries, one per image in batch
- List of dictionaries. Each List entry is one image. Each dict contains another dict for each detected nucleus.
For each nucleus, the following information are returned: “bbox”, “centroid”, “contour”, “type_prob”, “type”
- Return type:
Tuple[torch.Tensor, List[Dict[str, Any]]]
- post_process_single_image(pred_map: numpy.ndarray) Tuple[numpy.ndarray, dict[int, dict]]
Process one single image and generate cell dictionary and instance predictions
- Parameters:
pred_map (np.ndarray) – Combined output of tp, np and hv branches, in the same order. Shape: (H, W, 4)
- Returns:
_description_
- Return type:
Tuple[np.ndarray, dict[int, dict]]
- loki2.models.cell_segmentation.postprocessing.stack_pred_maps(nuclei_type_map: numpy.ndarray, nuclei_binary_map: numpy.ndarray, hv_map: numpy.ndarray) numpy.ndarray
Creates the prediction map for HoVer-Net post-processing
Args: nuclei_binary_map:
nuclei_type_map (np.ndarray): Type prediction of nuclei. Shape: (B, H, W, self.num_nuclei_classes,) nuclei_binary_map (np.ndarray): Binary Nucleus Predictions. Shape: (B, H, W, 2) hv_map (np.ndarray): Horizontal-Vertical nuclei mapping. Shape: (B, H, W, 2)
- Returns:
A numpy array containing the stacked prediction maps. Shape [B, H, W, 4]
- Return type:
np.ndarray