target_assign

paddle.fluid.layers.target_assign(input, matched_indices, negative_indices=None, mismatch_value=None, name=None)[source]

This operator can be, for given the target bounding boxes or labels, to assign classification and regression targets to each prediction as well as weights to prediction. The weights is used to specify which prediction would not contribute to training loss.

For each instance, the output out and`out_weight` are assigned based on match_indices and negative_indices. Assumed that the row offset for each instance in input is called lod, this operator assigns classification/regression targets by performing the following steps:

  1. Assigning all outputs based on match_indices:

If id = match_indices[i][j] > 0,

    out[i][j][0 : K] = X[lod[i] + id][j % P][0 : K]
    out_weight[i][j] = 1.

Otherwise,

    out[j][j][0 : K] = {mismatch_value, mismatch_value, ...}
    out_weight[i][j] = 0.
  1. Assigning outputs based on neg_indices if neg_indices is provided:

Assumed that i-th instance in neg_indices is called neg_indice, for i-th instance:

for id in neg_indice:
    out[i][id][0 : K] = {mismatch_value, mismatch_value, ...}
    out_weight[i][id] = 1.0
Parameters
  • input (Variable) – This input is a 3D LoDTensor with shape [M, P, K]. Data type should be int32 or float32.

  • matched_indices (Variable) – The input matched indices is 2D Tenosr<int32> with shape [N, P], If MatchIndices[i][j] is -1, the j-th entity of column is not matched to any entity of row in i-th instance.

  • negative_indices (Variable, optional) – The input negative example indices are an optional input with shape [Neg, 1] and int32 type, where Neg is the total number of negative example indices.

  • mismatch_value (float32, optional) – Fill this value to the mismatched location.

  • name (string) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name.

Returns

A tuple(out, out_weight) is returned.

out (Variable): a 3D Tensor with shape [N, P, K] and same data type with input, N and P is the same as they are in matched_indices, K is the same as it in input of X.

out_weight (Variable): the weight for output with the shape of [N, P, 1]. Data type is float32.

Return type

tuple

Examples

import paddle.fluid as fluid
x = fluid.data(
    name='x',
    shape=[4, 20, 4],
    dtype='float',
    lod_level=1)
matched_id = fluid.data(
    name='indices',
    shape=[8, 20],
    dtype='int32')
trg, trg_weight = fluid.layers.target_assign(
    x,
    matched_id,
    mismatch_value=0)