<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/models/blob/v2.20.0/official/vision/modeling/layers/box_sampler.py#L22-L92) |

Creates a BoxSampler to sample positive and negative boxes.

    tfm.vision.layers.BoxSampler(
        num_samples: int = 512, foreground_fraction: float = 0.25, **kwargs
    )

<br />

<br />

<br />

| ## Args ||
|---|---|
| `num_samples` | An `int` of the number of sampled boxes per image. |
| `foreground_fraction` | A `float` in \[0, 1\], what percentage of boxes should be sampled from the positive examples. |
| `**kwargs` | Additional keyword arguments passed to Layer. |

<br />

## Methods

### `call`

[View source](https://github.com/tensorflow/models/blob/v2.20.0/official/vision/modeling/layers/box_sampler.py#L44-L85)

    call(
        positive_matches: tf.Tensor,
        negative_matches: tf.Tensor,
        ignored_matches: tf.Tensor
    )

Samples and selects positive and negative instances.

<br />

<br />

<br />

| Args ||
|---|---|
| `positive_matches` | A `bool` tensor of shape of \[batch, N\] where N is the number of instances. For each element, `True` means the instance corresponds to a positive example. |
| `negative_matches` | A `bool` tensor of shape of \[batch, N\] where N is the number of instances. For each element, `True` means the instance corresponds to a negative example. |
| `ignored_matches` | A `bool` tensor of shape of \[batch, N\] where N is the number of instances. For each element, `True` means the instance should be ignored. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A `tf.tensor` of shape of \[batch_size, K\], storing the indices of the sampled examples, where K is `num_samples`. ||

<br />