<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/mask_sampler.py#L102-L165) |

Samples and creates mask training targets.

    tfm.vision.layers.MaskSampler(
        mask_target_size: int, num_sampled_masks: int, **kwargs
    )

## Methods

### `call`

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

    call(
        candidate_rois: tf.Tensor,
        candidate_gt_boxes: tf.Tensor,
        candidate_gt_classes: tf.Tensor,
        candidate_gt_indices: tf.Tensor,
        gt_masks: tf.Tensor
    )

Samples and creates mask targets for training.

<br />

<br />

<br />

| Args ||
|---|---|
| `candidate_rois` | A [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) of shape of \[batch_size, N, 4\], where N is the number of candidate RoIs to be considered for mask sampling. It includes both positive and negative RoIs. The `num_mask_samples_per_image` positive RoIs will be sampled to create mask training targets. |
| `candidate_gt_boxes` | A [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) of shape of \[batch_size, N, 4\], storing the corresponding groundtruth boxes to the `candidate_rois`. |
| `candidate_gt_classes` | A [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) of shape of \[batch_size, N\], storing the corresponding groundtruth classes to the `candidate_rois`. 0 in the tensor corresponds to the background class, i.e. negative RoIs. |
| `candidate_gt_indices` | A [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) of shape \[batch_size, N\], storing the corresponding groundtruth instance indices to the `candidate_gt_boxes`, i.e. gt_boxes\[candidate_gt_indices\[:, i\]\] = candidate_gt_boxes\[:, i\], where gt_boxes which is of shape \[batch_size, MAX_INSTANCES, 4\], M \>= N, is the superset of candidate_gt_boxes. |
| `gt_masks` | A [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) of \[batch_size, MAX_INSTANCES, mask_height, mask_width\] containing all the groundtruth masks which sample masks are drawn from. after sampling. The output masks are resized w.r.t the sampled RoIs. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| `foreground_rois` | A [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) of shape of \[batch_size, K, 4\] storing the RoI that corresponds to the sampled foreground masks, where K = num_mask_samples_per_image. |
| `foreground_classes` | A [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) of shape of \[batch_size, K\] storing the classes corresponding to the sampled foreground masks. |
| `cropoped_foreground_masks` | A [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) of shape of \[batch_size, K, mask_target_size, mask_target_size\] storing the cropped foreground masks used for training. |

<br />