- paddle.fluid.layers.detection. bipartite_match ( dist_matrix, match_type=None, dist_threshold=None, name=None )
This operator implements a greedy bipartite matching algorithm, which is used to obtain the matching with the maximum distance based on the input distance matrix. For input 2D matrix, the bipartite matching algorithm can find the matched column for each row (matched means the largest distance), also can find the matched row for each column. And this operator only calculate matched indices from column to row. For each instance, the number of matched indices is the column number of the input distance matrix. The OP only supports CPU.
There are two outputs, matched indices and distance. A simple description, this algorithm matched the best (maximum distance) row entity to the column entity and the matched indices are not duplicated in each row of ColToRowMatchIndices. If the column entity is not matched any row entity, set -1 in ColToRowMatchIndices.
NOTE: the input DistMat can be LoDTensor (with LoD) or Tensor. If LoDTensor with LoD, the height of ColToRowMatchIndices is batch size. If Tensor, the height of ColToRowMatchIndices is 1.
NOTE: This API is a very low level API. It is used by
ssd_losslayer. Please consider to use
dist_matrix (Variable) – This input is a 2-D LoDTensor with shape [K, M]. The data type is float32 or float64. It is pair-wise distance matrix between the entities represented by each row and each column. For example, assumed one entity is A with shape [K], another entity is B with shape [M]. The dist_matrix[i][j] is the distance between A[i] and B[j]. The bigger the distance is, the better matching the pairs are. NOTE: This tensor can contain LoD information to represent a batch of inputs. One instance of this batch can contain different numbers of entities.
match_type (str, optional) – The type of matching method, should be ‘bipartite’ or ‘per_prediction’. None (‘bipartite’) by default.
dist_threshold (float32, optional) – If match_type is ‘per_prediction’, this threshold is to determine the extra matching bboxes based on the maximum distance, 0.5 by default.
name (str, optional) – For detailed information, please refer to Name. Usually name is no need to set and None by default.
matched_indices(Variable): A 2-D Tensor with shape [N, M]. The data type is int32. N is the batch size. If match_indices[i][j] is -1, it means B[j] does not match any entity in i-th instance. Otherwise, it means B[j] is matched to row match_indices[i][j] in i-th instance. The row number of i-th instance is saved in match_indices[i][j].
matched_distance(Variable): A 2-D Tensor with shape [N, M]. The data type is float32. N is batch size. If match_indices[i][j] is -1, match_distance[i][j] is also -1.0. Otherwise, assumed match_distance[i][j] = d, and the row offsets of each instance are called LoD. Then match_distance[i][j] = dist_matrix[d+LoD[i]][j].
- Return type
>>> import paddle.fluid as fluid >>> x = fluid.data(name='x', shape=[None, 4], dtype='float32') >>> y = fluid.data(name='y', shape=[None, 4], dtype='float32') >>> iou = fluid.layers.iou_similarity(x=x, y=y) >>> matched_indices, matched_dist = fluid.layers.bipartite_match(iou)