# tf.contrib.opt.ModelAverageCustomGetter

<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/opt/python/training/model_average_optimizer.py#L36-L100) |

Custom_getter class is used to do.

    tf.contrib.opt.ModelAverageCustomGetter(
        worker_device
    )

1. Change trainable variables to local collection and place them at worker device
2. Generate global variables Notice that the class should be used with tf.replica_device_setter, so that the global center variables and global step variable can be placed at ps device. Besides, use 'tf.compat.v1.get_variable' instead of 'tf.Variable' to use this custom getter.

For example,
ma_custom_getter = ModelAverageCustomGetter(worker_device)
with tf.device(
tf.compat.v1.train.replica_device_setter(
worker_device=worker_device,
ps_device="/job:ps/cpu:0",
cluster=cluster)),
tf.compat.v1.variable_scope('',custom_getter=ma_custom_getter):
hid_w = tf.compat.v1.get_variable(
initializer=tf.random.truncated_normal(
\[IMAGE_PIXELS \* IMAGE_PIXELS, FLAGS.hidden_units\],
stddev=1.0 / IMAGE_PIXELS),
name="hid_w")
hid_b =
tf.compat.v1.get_variable(initializer=tf.zeros(\[FLAGS.hidden_units\]),
name="hid_b")

<br />

<br />

<br />

| ## Args ||
|---|---|
| `worker_device` | String. Name of the `worker` job. |

<br />

## Methods

### `__call__`

[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/contrib/opt/python/training/model_average_optimizer.py#L75-L100)

    __call__(
        getter, name, trainable, collections, *args, **kwargs
    )

Call self as a function.