@@ -210,53 +210,68 @@ def bipartite_match(dist_matrix,
210
210
dist_threshold = None ,
211
211
name = None ):
212
212
"""
213
- **Bipartite matchint operator**
214
-
215
- This operator is a greedy bipartite matching algorithm, which is used to
216
- obtain the matching with the maximum distance based on the input
213
+ This operator implements a greedy bipartite matching algorithm, which is
214
+ used to obtain the matching with the maximum distance based on the input
217
215
distance matrix. For input 2D matrix, the bipartite matching algorithm can
218
- find the matched column for each row, also can find the matched row for
219
- each column. And this operator only calculate matched indices from column
220
- to row. For each instance, the number of matched indices is the number of
221
- of columns of the input ditance matrix.
222
-
223
- There are two outputs to save matched indices and distance.
224
- A simple description, this algothrim matched the best (maximum distance)
216
+ find the matched column for each row (matched means the largest distance),
217
+ also can find the matched row for each column. And this operator only
218
+ calculate matched indices from column to row. For each instance,
219
+ the number of matched indices is the column number of the input distance
220
+ matrix.
221
+
222
+ There are two outputs, matched indices and distance.
223
+ A simple description, this algorithm matched the best (maximum distance)
225
224
row entity to the column entity and the matched indices are not duplicated
226
225
in each row of ColToRowMatchIndices. If the column entity is not matched
227
226
any row entity, set -1 in ColToRowMatchIndices.
228
227
229
- Please note that the input DistMat can be LoDTensor (with LoD) or Tensor.
228
+ NOTE: the input DistMat can be LoDTensor (with LoD) or Tensor.
230
229
If LoDTensor with LoD, the height of ColToRowMatchIndices is batch size.
231
230
If Tensor, the height of ColToRowMatchIndices is 1.
232
231
232
+ NOTE: This API is a very low level API. It is used by :code:`ssd_loss`
233
+ layer. Please consider to use :code:`ssd_loss` instead.
234
+
233
235
Args:
234
236
dist_matrix(Variable): This input is a 2-D LoDTensor with shape
235
237
[K, M]. It is pair-wise distance matrix between the entities
236
238
represented by each row and each column. For example, assumed one
237
239
entity is A with shape [K], another entity is B with shape [M]. The
238
- dist_matirx[i][j] is the distance between A[i] and B[j]. The bigger
239
- the distance is, the better macthing the pairs are. Please note,
240
- This tensor can contain LoD information to represent a batch of
241
- inputs. One instance of this batch can contain different numbers of
242
- entities.
240
+ dist_matrix[i][j] is the distance between A[i] and B[j]. The bigger
241
+ the distance is, the better matching the pairs are.
242
+
243
+ NOTE: This tensor can contain LoD information to represent a batch
244
+ of inputs. One instance of this batch can contain different numbers
245
+ of entities.
243
246
match_type(string|None): The type of matching method, should be
244
- 'bipartite' or 'per_prediction', 'bipartite' by defalut .
247
+ 'bipartite' or 'per_prediction'. [default 'bipartite'] .
245
248
dist_threshold(float|None): If `match_type` is 'per_prediction',
246
249
this threshold is to determine the extra matching bboxes based
247
- on the maximum distance, 0.5 by defalut .
250
+ on the maximum distance, 0.5 by default .
248
251
Returns:
249
- match_indices(Variable): A 2-D Tensor with shape [N, M] in int type.
250
- N is the batch size. If match_indices[i][j] is -1, it
251
- means B[j] does not match any entity in i-th instance.
252
- Otherwise, it means B[j] is matched to row
253
- match_indices[i][j] in i-th instance. The row number of
254
- i-th instance is saved in match_indices[i][j].
255
- match_distance(Variable): A 2-D Tensor with shape [N, M] in float type.
256
- N is batch size. If match_indices[i][j] is -1,
257
- match_distance[i][j] is also -1.0. Otherwise, assumed
258
- match_distance[i][j] = d, and the row offsets of each instance
259
- are called LoD. Then match_distance[i][j] = dist_matrix[d+LoD[i]][j].
252
+ tuple: a tuple with two elements is returned. The first is
253
+ matched_indices, the second is matched_distance.
254
+
255
+ The matched_indices is a 2-D Tensor with shape [N, M] in int type.
256
+ N is the batch size. If match_indices[i][j] is -1, it
257
+ means B[j] does not match any entity in i-th instance.
258
+ Otherwise, it means B[j] is matched to row
259
+ match_indices[i][j] in i-th instance. The row number of
260
+ i-th instance is saved in match_indices[i][j].
261
+
262
+ The matched_distance is a 2-D Tensor with shape [N, M] in float type
263
+ . N is batch size. If match_indices[i][j] is -1,
264
+ match_distance[i][j] is also -1.0. Otherwise, assumed
265
+ match_distance[i][j] = d, and the row offsets of each instance
266
+ are called LoD. Then match_distance[i][j] =
267
+ dist_matrix[d+LoD[i]][j].
268
+
269
+ Examples:
270
+
271
+ >>> x = fluid.layers.data(name='x', shape=[4], dtype='float32')
272
+ >>> y = fluid.layers.data(name='y', shape=[4], dtype='float32')
273
+ >>> iou = fluid.layers.iou_similarity(x=x, y=y)
274
+ >>> matched_indices, matched_dist = fluid.layers.bipartite_match(iou)
260
275
"""
261
276
helper = LayerHelper ('bipartite_match' , ** locals ())
262
277
match_indices = helper .create_tmp_variable (dtype = 'int32' )
@@ -364,15 +379,15 @@ def ssd_loss(location,
364
379
normalize = True ,
365
380
sample_size = None ):
366
381
"""
367
- **Multi-box loss layer for object dection algorithm of SSD**
382
+ **Multi-box loss layer for object detection algorithm of SSD**
368
383
369
384
This layer is to compute dection loss for SSD given the location offset
370
385
predictions, confidence predictions, prior boxes and ground-truth boudding
371
386
boxes and labels, and the type of hard example mining. The returned loss
372
387
is a weighted sum of the localization loss (or regression loss) and
373
388
confidence loss (or classification loss) by performing the following steps:
374
389
375
- 1. Find matched boundding box by bipartite matching algorithm.
390
+ 1. Find matched bounding box by bipartite matching algorithm.
376
391
377
392
1.1 Compute IOU similarity between ground-truth boxes and prior boxes.
378
393
@@ -435,7 +450,7 @@ def ssd_loss(location,
435
450
mining_type (str): The hard example mining type, should be 'hard_example'
436
451
or 'max_negative', now only support `max_negative`.
437
452
normalize (bool): Whether to normalize the SSD loss by the total number
438
- of output locations, True by defalut .
453
+ of output locations, True by default .
439
454
sample_size (int): The max sample size of negative box, used only when
440
455
mining_type is 'hard_example'.
441
456
0 commit comments