<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/video_classification.py#L30-L369) |

A task for video classification.

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

#### View aliases


**Main aliases**

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

<br />

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

<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/core/base_task.py#L325-L342)

    aggregate_logs(
        state, step_logs
    )

Optional aggregation over logs returned from a validation step.

Given step_logs from a validation step, this function aggregates the logs
after each eval_step() (see eval_reduce() function in
official/core/base_trainer.py). It runs on CPU and can be used to aggregate
metrics during validation, when there are too many metrics that cannot fit
into TPU memory. Note that this may increase latency due to data transfer
between TPU and CPU. Also, the step output from a validation step may be a
tuple with elements from replicas, and a concatenation of the elements is
needed in such case.

<br />

<br />

<br />

| Args ||
|---|---|
| `state` | The current state of training, for example, it can be a sequence of metrics. |
| `step_logs` | Logs from a validation step. Can be a dictionary. |

<br />

### `build_inputs`

[View source](https://github.com/tensorflow/models/blob/v2.20.0/official/vision/tasks/video_classification.py#L126-L157)

    build_inputs(
        params: https://www.tensorflow.org/api_docs/python/tfm/vision/configs/video_classification/DataConfig,
        input_context: Optional[tf.distribute.InputContext] = None
    )

Builds classification input.

### `build_losses`

[View source](https://github.com/tensorflow/models/blob/v2.20.0/official/vision/tasks/video_classification.py#L159-L207)

    build_losses(
        labels: Any, model_outputs: Any, aux_losses: Optional[Any] = None
    )

Sparse categorical cross entropy loss.

<br />

<br />

<br />

| Args ||
|---|---|
| `labels` | labels. |
| `model_outputs` | Output logits of the classifier. |
| `aux_losses` | auxiliarly loss tensors, i.e. `losses` in keras.Model. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| The total loss tensor. ||

<br />

### `build_metrics`

[View source](https://github.com/tensorflow/models/blob/v2.20.0/official/vision/tasks/video_classification.py#L209-L239)

    build_metrics(
        training: bool = True
    )

Gets streaming metrics for training/validation.

### `build_model`

[View source](https://github.com/tensorflow/models/blob/v2.20.0/official/vision/tasks/video_classification.py#L57-L80)

    build_model()

Builds video classification 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/vision/tasks/video_classification.py#L357-L369)

    inference_step(
        features: tf.Tensor, model: tf_keras.Model
    )

Performs the forward step.

### `initialize`

[View source](https://github.com/tensorflow/models/blob/v2.20.0/official/vision/tasks/video_classification.py#L82-L105)

    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/vision/tasks/video_classification.py#L241-L255)

    process_metrics(
        metrics: List[Any], labels: Any, model_outputs: Any
    )

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. |

<br />

### `reduce_aggregated_logs`

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

    reduce_aggregated_logs(
        aggregated_logs, global_step: Optional[tf.Tensor] = None
    )

Optional reduce of aggregated logs over validation steps.

This function reduces aggregated logs at the end of validation, and can be
used to compute the final metrics. It runs on CPU and in each eval_end() in
base trainer (see eval_end() function in official/core/base_trainer.py).

<br />

<br />

<br />

| Args ||
|---|---|
| `aggregated_logs` | Aggregated logs over multiple validation steps. |
| `global_step` | An optional variable of global step. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A dictionary of reduced results. ||

<br />

### `train_step`

[View source](https://github.com/tensorflow/models/blob/v2.20.0/official/vision/tasks/video_classification.py#L257-L321)

    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/video_classification.py#L323-L355)

    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 />