<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/tasks/maskrcnn.py#L65-L643) |

A single-replica view of training procedure.

Inherits From: [`Task`](https://www.tensorflow.org/api_docs/python/tfm/core/base_task/Task)

#### View aliases


**Main aliases**

[`tfm.vision.maskrcnn.MaskRCNNTask`](https://www.tensorflow.org/api_docs/python/tfm/vision/MaskRCNNTask)

<br />

    tfm.vision.MaskRCNNTask(
        params, logging_dir: Optional[str] = None, name: Optional[str] = None
    )

Mask R-CNN task provides artifacts for training/evalution procedures,
including loading/iterating over Datasets, initializing the model, calculating
the loss, post-processing, and customized metrics with reduction.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `params` | the task configuration instance, which can be any of dataclass, ConfigDict, namedtuple, etc. |
| `logging_dir` | a string pointing to where the model, summaries etc. will be saved. You can also write additional stuff in this directory. |
| `name` | the task name. |

<br />

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `logging_dir` | <br /> <br /> |
| `task_config` | <br /> <br /> |

<br />

## Methods

### `aggregate_logs`

[View source](https://github.com/tensorflow/models/blob/v2.20.0/official/vision/tasks/maskrcnn.py#L528-L566)

    aggregate_logs(
        state: Optional[Any] = None, step_outputs: Optional[Dict[str, Any]] = None
    ) -> Optional[Any]

Optional aggregation over logs returned from a validation step.

### `build_inputs`

[View source](https://github.com/tensorflow/models/blob/v2.20.0/official/vision/tasks/maskrcnn.py#L131-L188)

    build_inputs(
        params: https://www.tensorflow.org/api_docs/python/tfm/vision/configs/maskrcnn/DataConfig,
        input_context: Optional[tf.distribute.InputContext] = None,
        dataset_fn: Optional[dataset_fn_lib.PossibleDatasetType] = None
    ) -> tf.data.Dataset

Builds input dataset.

### `build_losses`

[View source](https://github.com/tensorflow/models/blob/v2.20.0/official/vision/tasks/maskrcnn.py#L266-L302)

    build_losses(
        outputs: Mapping[str, Any],
        labels: Mapping[str, Any],
        aux_losses: Optional[Any] = None
    ) -> Dict[str, tf.Tensor]

Builds Mask R-CNN losses.

### `build_metrics`

[View source](https://github.com/tensorflow/models/blob/v2.20.0/official/vision/tasks/maskrcnn.py#L339-L388)

    build_metrics(
        training: bool = True
    )

Builds detection metrics.

### `build_model`

[View source](https://github.com/tensorflow/models/blob/v2.20.0/official/vision/tasks/maskrcnn.py#L74-L100)

    build_model()

Builds Mask R-CNN model.

### `create_optimizer`

[View source](https://github.com/tensorflow/models/blob/v2.20.0/official/core/base_task.py#L72-L111)

    @classmethod
    create_optimizer(
        optimizer_config: https://www.tensorflow.org/api_docs/python/tfm/optimization/OptimizationConfig,
        runtime_config: Optional[https://www.tensorflow.org/api_docs/python/tfm/core/base_task/RuntimeConfig] = None,
        dp_config: Optional[https://www.tensorflow.org/api_docs/python/tfm/core/base_task/DifferentialPrivacyConfig] = None
    )

Creates an TF optimizer from configurations.

<br />

<br />

<br />

| Args ||
|---|---|
| `optimizer_config` | the parameters of the Optimization settings. |
| `runtime_config` | the parameters of the runtime. |
| `dp_config` | the parameter of differential privacy. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A tf.optimizers.Optimizer object. ||

<br />

### `inference_step`

[View source](https://github.com/tensorflow/models/blob/v2.20.0/official/core/base_task.py#L311-L323)

    inference_step(
        inputs, model: tf_keras.Model
    )

Performs the forward step.

With distribution strategies, this method runs on devices.

<br />

<br />

<br />

| Args ||
|---|---|
| `inputs` | a dictionary of input tensors. |
| `model` | the keras.Model. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| Model outputs. ||

<br />

### `initialize`

[View source](https://github.com/tensorflow/models/blob/v2.20.0/official/vision/tasks/maskrcnn.py#L102-L129)

    initialize(
        model: tf_keras.Model
    )

Loads pretrained checkpoint.

### `process_compiled_metrics`

[View source](https://github.com/tensorflow/models/blob/v2.20.0/official/core/base_task.py#L210-L221)

    process_compiled_metrics(
        compiled_metrics, labels, model_outputs
    )

Process and update compiled_metrics.

call when using compile/fit API.

<br />

<br />

<br />

| Args ||
|---|---|
| `compiled_metrics` | the compiled metrics (model.compiled_metrics). |
| `labels` | a tensor or a nested structure of tensors. |
| `model_outputs` | a tensor or a nested structure of tensors. For example, output of the keras model built by self.build_model. |

<br />

### `process_metrics`

[View source](https://github.com/tensorflow/models/blob/v2.20.0/official/core/base_task.py#L194-L208)

    process_metrics(
        metrics, labels, model_outputs, **kwargs
    )

Process and update metrics.

Called when using custom training loop API.

<br />

<br />

<br />

| Args ||
|---|---|
| `metrics` | a nested structure of metrics objects. The return of function self.build_metrics. |
| `labels` | a tensor or a nested structure of tensors. |
| `model_outputs` | a tensor or a nested structure of tensors. For example, output of the keras model built by self.build_model. |
| `**kwargs` | other args. |

<br />

### `reduce_aggregated_logs`

[View source](https://github.com/tensorflow/models/blob/v2.20.0/official/vision/tasks/maskrcnn.py#L616-L643)

    reduce_aggregated_logs(
        aggregated_logs: Dict[str, Any], global_step: Optional[tf.Tensor] = None
    ) -> Dict[str, tf.Tensor]

Optional reduce of aggregated logs over validation steps.

### `train_step`

[View source](https://github.com/tensorflow/models/blob/v2.20.0/official/vision/tasks/maskrcnn.py#L390-L448)

    train_step(
        inputs: Tuple[Any, Any],
        model: tf_keras.Model,
        optimizer: tf_keras.optimizers.Optimizer,
        metrics: Optional[List[Any]] = None
    )

Does forward and backward.

<br />

<br />

<br />

| Args ||
|---|---|
| `inputs` | a dictionary of input tensors. |
| `model` | the model, forward pass definition. |
| `optimizer` | the optimizer for this training step. |
| `metrics` | a nested structure of metrics objects. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A dictionary of logs. ||

<br />

### `validation_step`

[View source](https://github.com/tensorflow/models/blob/v2.20.0/official/vision/tasks/maskrcnn.py#L493-L526)

    validation_step(
        inputs: Tuple[Any, Any],
        model: tf_keras.Model,
        metrics: Optional[List[Any]] = None
    )

Validatation step.

<br />

<br />

<br />

| Args ||
|---|---|
| `inputs` | a dictionary of input tensors. |
| `model` | the keras.Model. |
| `metrics` | a nested structure of metrics objects. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A dictionary of logs. ||

<br />

<br />

<br />

<br />

| ## Class Variables ||
|---|---|
| loss | `'loss'` |

<br />