# tf.compat.v1.VariableScope

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.14.0/tensorflow/python/ops/variable_scope.py#L1112-L1420) |

Variable scope object to carry defaults to provide to `get_variable`.

    tf.compat.v1.VariableScope(
        reuse,
        name='',
        initializer=None,
        regularizer=None,
        caching_device=None,
        partitioner=None,
        custom_getter=None,
        name_scope='',
        dtype=https://www.tensorflow.org/versions/r2.14/api_docs/python/tf/dtypes#float32,
        use_resource=None,
        constraint=None
    )

Many of the arguments we need for `get_variable` in a variable store are most
easily handled with a context. This object is used for the defaults.

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `name` | name of the current scope, used as prefix in get_variable. |
| `initializer` | default initializer passed to get_variable. |
| `regularizer` | default regularizer passed to get_variable. |
| `reuse` | Boolean, None, or tf.compat.v1.AUTO_REUSE, setting the reuse in get_variable. When eager execution is enabled this argument is always forced to be False. |
| `caching_device` | string, callable, or None: the caching device passed to get_variable. |
| `partitioner` | callable or `None`: the partitioner passed to `get_variable`. |
| `custom_getter` | default custom getter passed to get_variable. |
| `name_scope` | The name passed to [`tf.name_scope`](https://www.tensorflow.org/versions/r2.14/api_docs/python/tf/name_scope). |
| `dtype` | default type passed to get_variable (defaults to DT_FLOAT). |
| `use_resource` | if False, create a normal Variable; if True create an experimental ResourceVariable with well-defined semantics. Defaults to False (will later change to True). When eager execution is enabled this argument is always forced to be True. |
| `constraint` | An optional projection function to be applied to the variable after being updated by an `Optimizer` (e.g. used to implement norm constraints or value constraints for layer weights). The function must take as input the unprojected Tensor representing the value of the variable and return the Tensor for the projected value (which must have the same shape). Constraints are not safe to use when doing asynchronous distributed training. |
| `original_name_scope` | <br /> <br /> |

<br />

## Methods

### `get_collection`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.14.0/tensorflow/python/ops/variable_scope.py#L1258-L1261)

    get_collection(
        name
    )

Get this scope's variables.

### `get_variable`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.14.0/tensorflow/python/ops/variable_scope.py#L1275-L1345)

    get_variable(
        var_store,
        name,
        shape=None,
        dtype=None,
        initializer=None,
        regularizer=None,
        reuse=None,
        trainable=None,
        collections=None,
        caching_device=None,
        partitioner=None,
        validate_shape=True,
        use_resource=None,
        custom_getter=None,
        constraint=None,
        synchronization=https://www.tensorflow.org/versions/r2.14/api_docs/python/tf/VariableSynchronization#AUTO,
        aggregation=https://www.tensorflow.org/versions/r2.14/api_docs/python/tf/compat/v1/VariableAggregation#NONE
    )

Gets an existing variable with this name or create a new one.

### `global_variables`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.14.0/tensorflow/python/ops/variable_scope.py#L1267-L1269)

    global_variables()

Get this scope's global variables.

### `local_variables`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.14.0/tensorflow/python/ops/variable_scope.py#L1271-L1273)

    local_variables()

Get this scope's local variables.

### `reuse_variables`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.14.0/tensorflow/python/ops/variable_scope.py#L1220-L1222)

    reuse_variables()

Reuse variables in this scope.

### `set_caching_device`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.14.0/tensorflow/python/ops/variable_scope.py#L1243-L1248)

    set_caching_device(
        caching_device
    )

Set caching_device for this scope.

### `set_custom_getter`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.14.0/tensorflow/python/ops/variable_scope.py#L1254-L1256)

    set_custom_getter(
        custom_getter
    )

Set custom getter for this scope.

### `set_dtype`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.14.0/tensorflow/python/ops/variable_scope.py#L1228-L1230)

    set_dtype(
        dtype
    )

Set data type for this scope.

### `set_initializer`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.14.0/tensorflow/python/ops/variable_scope.py#L1224-L1226)

    set_initializer(
        initializer
    )

Set initializer for this scope.

### `set_partitioner`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.14.0/tensorflow/python/ops/variable_scope.py#L1250-L1252)

    set_partitioner(
        partitioner
    )

Set partitioner for this scope.

### `set_regularizer`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.14.0/tensorflow/python/ops/variable_scope.py#L1239-L1241)

    set_regularizer(
        regularizer
    )

Set regularizer for this scope.

### `set_use_resource`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.14.0/tensorflow/python/ops/variable_scope.py#L1232-L1237)

    set_use_resource(
        use_resource
    )

Sets whether to use ResourceVariables for this scope.

### `trainable_variables`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.14.0/tensorflow/python/ops/variable_scope.py#L1263-L1265)

    trainable_variables()

Get this scope's trainable variables.