# tf.contrib.learn.ModelFnOps

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/contrib/learn/python/learn/estimators/model_fn.py#L70-L307) |

Ops returned from a model_fn.

    tf.contrib.learn.ModelFnOps(
        mode, predictions=None, loss=None, train_op=None, eval_metric_ops=None,
        output_alternatives=None, training_chief_hooks=None, training_hooks=None,
        scaffold=None
    )

THIS CLASS IS DEPRECATED. See
[contrib/learn/README.md](https://www.tensorflow.org/code/tensorflow/contrib/learn/README.md)
for general migration instructions.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `mode` | One of `ModeKeys`. Specifies if this training, evaluation or prediction. |
| `predictions` | Predictions `Tensor` or dict of `Tensor`. |
| `loss` | Training loss `Tensor`. |
| `train_op` | Op for the training step. |
| `eval_metric_ops` | Dict of metric results keyed by name. The values of the dict are the results of calling a metric function, such as `Tensor`. |
| `output_alternatives` | a dict of `{submodel_name: (problem_type, {tensor_name: Tensor})}`, where `submodel_name` is a submodel identifier that should be consistent across the pipeline (here likely taken from the name of each `Head`, for models that use them), `problem_type` is a `ProblemType`, `tensor_name` is a symbolic name for an output Tensor possibly but not necessarily taken from `PredictionKey`, and `Tensor` is the corresponding output Tensor itself. |
| `training_chief_hooks` | A list of `SessionRunHook` objects that will be run on the chief worker during training. |
| `training_hooks` | A list of `SessionRunHook` objects that will be run on all workers during training. |
| `scaffold` | A [`tf.compat.v1.train.Scaffold`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/train/Scaffold) object that can be used to set initialization, saver, and more to be used in training. |

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | If validation fails. |

<br />

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `predictions` | <br /> <br /> |
| `loss` | <br /> <br /> |
| `train_op` | <br /> <br /> |
| `eval_metric_ops` | <br /> <br /> |
| `output_alternatives` | <br /> <br /> |
| `training_chief_hooks` | <br /> <br /> |
| `training_hooks` | <br /> <br /> |
| `scaffold` | <br /> <br /> |
| `mode` | <br /> <br /> |

<br />

## Methods

### `estimator_spec`

[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/contrib/learn/python/learn/estimators/model_fn.py#L212-L307)

    estimator_spec(
        default_serving_output_alternative_key=None
    )

Creates an equivalent `EstimatorSpec`.

<br />

<br />

<br />

| Args ||
|---|---|
| `default_serving_output_alternative_key` | Required for multiple heads. If you have multiple entries in `output_alternatives` dict (comparable to multiple heads), `EstimatorSpec` requires a default head that will be used if a Servo request does not explicitly mention which head to infer on. Pass the key of the output alternative here that you want to designate as default. A separate ExportOutpout for this default head will be added to the export_outputs dict with the special key saved_model.DEFAULT_SERVING_SIGNATURE_DEF_KEY, unless there is already an enry in output_alternatives with this special key. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| Instance of `EstimatorSpec` that is equivalent to this `ModelFnOps` ||

<br />

<br />

<br />

<br />

| Raises ||
|---|---|
| `ValueError` | If problem type is unknown. |

<br />