# tf_agents.policies.SavedModelPyTFEagerPolicy

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/policies/py_tf_eager_policy.py#L149-L293) |

Exposes a numpy API for saved_model policies in Eager mode.

Inherits From: [`PyTFEagerPolicyBase`](https://www.tensorflow.org/agents/api_docs/python/tf_agents/policies/py_tf_eager_policy/PyTFEagerPolicyBase), [`PyPolicy`](https://www.tensorflow.org/agents/api_docs/python/tf_agents/policies/py_policy/PyPolicy)

#### View aliases


**Main aliases**

[`tf_agents.policies.py_tf_eager_policy.SavedModelPyTFEagerPolicy`](https://www.tensorflow.org/agents/api_docs/python/tf_agents/policies/SavedModelPyTFEagerPolicy)

<br />

    tf_agents.policies.SavedModelPyTFEagerPolicy(
        model_path: Text,
        time_step_spec: Optional[https://www.tensorflow.org/agents/api_docs/python/tf_agents/trajectories/TimeStep] = None,
        action_spec: Optional[https://www.tensorflow.org/agents/api_docs/python/tf_agents/typing/types#DistributionSpecV2] = None,
        policy_state_spec: https://www.tensorflow.org/agents/api_docs/python/tf_agents/typing/types/NestedTensorSpec = (),
        info_spec: https://www.tensorflow.org/agents/api_docs/python/tf_agents/typing/types/NestedTensorSpec = (),
        load_specs_from_pbtxt: bool = False,
        use_tf_function: bool = False,
        batch_time_steps=True
    )

### Used in the notebooks

| Used in the tutorials |
|---|
| - [Checkpointer and PolicySaver](https://www.tensorflow.org/agents/tutorials/10_checkpointer_policysaver_tutorial) |

<br />

<br />

<br />

| ## Args ||
|---|---|
| `model_path` | Path to a saved_model generated by the `policy_saver`. |
| `time_step_spec` | Optional nested structure of ArraySpecs describing the policy's `time_step_spec`. This is not used by the SavedModelPyTFEagerPolicy, but may be accessed by other objects as it is part of the public policy API. |
| `action_spec` | Optional nested structure of `ArraySpecs` describing the policy's `action_spec`. This is not used by the SavedModelPyTFEagerPolicy, but may be accessed by other objects as it is part of the public policy API. |
| `policy_state_spec` | Optional nested structure of `ArraySpecs` describing the policy's `policy_state_spec`. This is not used by the SavedModelPyTFEagerPolicy, but may be accessed by other objects as it is part of the public policy API. |
| `info_spec` | Optional nested structure of `ArraySpecs` describing the policy's `info_spec`. This is not used by the SavedModelPyTFEagerPolicy, but may be accessed by other objects as it is part of the public policy API. |
| `load_specs_from_pbtxt` | If True the specs will be loaded from the proto file generated by the `policy_saver`. |
| `use_tf_function` | See PyTFEagerPolicyBase. |
| `batch_time_steps` | See PyTFEagerPolicyBase. |

<br />

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `action_spec` | Describes the ArraySpecs of the np.Array returned by `action()`. <br /> `action` can be a single np.Array, or a nested dict, list or tuple of np.Array. |
| `collect_data_spec` | Describes the data collected when using this policy with an environment. |
| `info_spec` | Describes the Arrays emitted as info by `action()`. |
| `observation_and_action_constraint_splitter` | <br /> <br /> |
| `policy_state_spec` | Describes the arrays expected by functions with `policy_state` as input. |
| `policy_step_spec` | Describes the output of `action()`. |
| `time_step_spec` | Describes the `TimeStep` np.Arrays expected by `action(time_step)`. |
| `trajectory_spec` | Describes the data collected when using this policy with an environment. |

<br />

## Methods

### `action`

[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/policies/py_policy.py#L147-L169)

    action(
        time_step: https://www.tensorflow.org/agents/api_docs/python/tf_agents/trajectories/TimeStep,
        policy_state: https://www.tensorflow.org/agents/api_docs/python/tf_agents/typing/types/NestedArray = (),
        seed: Optional[types.Seed] = None
    ) -> https://www.tensorflow.org/agents/api_docs/python/tf_agents/trajectories/PolicyStep

Generates next action given the time_step and policy_state.

<br />

<br />

<br />

| Args ||
|---|---|
| `time_step` | A `TimeStep` tuple corresponding to `time_step_spec()`. |
| `policy_state` | An optional previous policy_state. |
| `seed` | Seed to use if action uses sampling (optional). |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A PolicyStep named tuple containing: `action`: A nest of action Arrays matching the `action_spec()`. `state`: A nest of policy states to be fed into the next call to action. `info`: Optional side information such as action log probabilities. ||

<br />

### `get_initial_state`

[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/policies/py_policy.py#L134-L145)

    get_initial_state(
        batch_size: Optional[int] = None
    ) -> https://www.tensorflow.org/agents/api_docs/python/tf_agents/typing/types/NestedArray

Returns an initial state usable by the policy.

<br />

<br />

<br />

| Args ||
|---|---|
| `batch_size` | An optional batch size. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| An initial policy state. ||

<br />

### `get_metadata`

[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/policies/py_tf_eager_policy.py#L246-L248)

    get_metadata()

Returns the metadata of the saved model.

### `get_train_step`

[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/policies/py_tf_eager_policy.py#L238-L240)

    get_train_step() -> https://www.tensorflow.org/agents/api_docs/python/tf_agents/typing/types/Int

Returns the training global step of the saved model.

### `get_train_step_from_last_restored_checkpoint_path`

[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/policies/py_tf_eager_policy.py#L242-L244)

    get_train_step_from_last_restored_checkpoint_path() -> Optional[int]

Returns the training step of the restored checkpoint.

### `update_from_checkpoint`

[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/policies/py_tf_eager_policy.py#L253-L289)

    update_from_checkpoint(
        checkpoint_path: Text
    )

Allows users to update saved_model variables directly from a checkpoint.

`checkpoint_path` is a path that was passed to either [`PolicySaver.save()`](https://www.tensorflow.org/agents/api_docs/python/tf_agents/policies/PolicySaver#save)
or [`PolicySaver.save_checkpoint()`](https://www.tensorflow.org/agents/api_docs/python/tf_agents/policies/PolicySaver#save_checkpoint). The policy looks for set of checkpoint
files with the file prefix \`/variables/variables'

<br />

<br />

<br />

| Args ||
|---|---|
| `checkpoint_path` | Path to the checkpoint to restore and use to udpate this policy. |

<br />

### `variables`

[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/policies/py_tf_eager_policy.py#L250-L251)

    variables()