Consensus (empanada.consensus)#

empanada.consensus.average_edge_between_clusters(G, cluster1, cluster2, key='iou')[source]#

Calculates the average edge weight between two groups of nodes in a graph.

Parameters
  • G – nx.Graph containing the nodes in cluster1 and cluster2

  • cluster1 – List of nodes in G

  • cluster2 – List of nodes in G

  • key – Name of the edge weight.

Returns

Float, the average edge weight across clusters.

Return type

avg_weight

empanada.consensus.bounding_box_screening(boxes, source_indices)[source]#

Merges together clusters in the cluster graph iteratively.

Parameters
  • boxes – Array of size (n, 4) or (n, 6) where bounding box is defined as (y1, x1, y2, x2) or (z1, y1, x1, z2, y2, x2).

  • source_indices – Array of size (n,) that records the source of each bounding box. Bounding boxes from the same source are always screened.

Returns

Array of size (k, 2). Each item is a unique pair of bounding boxes from boxes that have non-trivial overlap with each other.

Return type

box_matches

empanada.consensus.create_graph_of_clusters(G, cluster_iou_thr)[source]#

Creates a graph in which each node is a group of nodes that have IoU greater than cluster_iou_thr.

Parameters
  • G – nx.Graph containing detection nodes

  • cluster_iou_thr – Minimum IoU score between nodes for them to be put into the same group.

Returns

nx.Graph containing the grouped detection nodes. Nodes are groups of detections and edges denote groups that have overlap with each other.

Return type

cluster_graph

empanada.consensus.merge_clusters(G)[source]#

Merges together clusters in the cluster graph iteratively.

Parameters

G – nx.Graph containing nodes that represent groups of detections.

Returns

nx.Graph containing nodes that represent the merged groups of detections.

Return type

H

empanada.consensus.merge_instances(instances_dict)[source]#

Merge arbitrary number of instances. From dict of instance_id and instance_attrs.

empanada.consensus.merge_objects_from_trackers(object_trackers, pixel_vote_thr=2, cluster_iou_thr=0.75, bypass=False)[source]#

Performs the consensus creation algorithm for instances from an arbitrary number of trackers (see empanada.inference.trackers).

Parameters
  • object_trackers – List of empanada.inference.InstanceTracker

  • pixel_vote_thr – Integer. Number of votes for a pixel/voxel to be in the consensus segmentation. Default 2, assumes there are 3 object trackers.

  • cluster_iou_thr – Float. IoU threshold for merging groups of instances. Default 0.75.

  • bypass – Bool. If True, instances that appear in just 1 of the object trackers can be included in the consensus. This will only affect the final segmentation if pixel_vote_thr < 0.5 * len(object_trackers). Default False.

Returns

A nested dictionary of instances. Each key is an instance_id. Values are themselves dictionaries that contain the bounding box and run length encoding of the instance (‘boxes’, ‘starts’, ‘runs’).

Return type

instances

empanada.consensus.merge_overlapping(cluster_instances)[source]#

Merges together instances that have non-trivial overlap with each other.

empanada.consensus.push_cluster(G, src, dst)[source]#

Merges groups from two nodes in a cluster_graph and removes their edge.