Gets an existing model variable with these parameters or creates a new one. Args: name: the name of the new or existing variable. shape: shape of the new or existing variable. dtype: type of the new or existing variable (defaults to `DT_FLOAT`). initializer: initializer for the va
(name,
shape=None,
dtype=dtypes.float32,
initializer=None,
regularizer=None,
trainable=True,
collections=None,
caching_device=None,
device=None,
partitioner=None,
custom_getter=None,
use_resource=None,
synchronization=variables.VariableSynchronization.AUTO,
aggregation=variables.VariableAggregation.NONE)
| 283 | |
| 284 | @contrib_add_arg_scope |
| 285 | def model_variable(name, |
| 286 | shape=None, |
| 287 | dtype=dtypes.float32, |
| 288 | initializer=None, |
| 289 | regularizer=None, |
| 290 | trainable=True, |
| 291 | collections=None, |
| 292 | caching_device=None, |
| 293 | device=None, |
| 294 | partitioner=None, |
| 295 | custom_getter=None, |
| 296 | use_resource=None, |
| 297 | synchronization=variables.VariableSynchronization.AUTO, |
| 298 | aggregation=variables.VariableAggregation.NONE): |
| 299 | """Gets an existing model variable with these parameters or creates a new one. |
| 300 | |
| 301 | Args: |
| 302 | name: the name of the new or existing variable. |
| 303 | shape: shape of the new or existing variable. |
| 304 | dtype: type of the new or existing variable (defaults to `DT_FLOAT`). |
| 305 | initializer: initializer for the variable if one is created. |
| 306 | regularizer: a (Tensor -> Tensor or None) function; the result of applying |
| 307 | it on a newly created variable will be added to the collection |
| 308 | GraphKeys.REGULARIZATION_LOSSES and can be used for regularization. |
| 309 | trainable: If `True` also add the variable to the graph collection |
| 310 | `GraphKeys.TRAINABLE_VARIABLES` (see `tf.Variable`). |
| 311 | collections: A list of collection names to which the Variable will be added. |
| 312 | Note that the variable is always also added to the |
| 313 | `GraphKeys.GLOBAL_VARIABLES` and `GraphKeys.MODEL_VARIABLES` collections. |
| 314 | caching_device: Optional device string or function describing where the |
| 315 | Variable should be cached for reading. Defaults to the Variable's device. |
| 316 | device: Optional device to place the variable. It can be an string or a |
| 317 | function that is called to get the device for the variable. |
| 318 | partitioner: Optional callable that accepts a fully defined `TensorShape` |
| 319 | and dtype of the `Variable` to be created, and returns a list of |
| 320 | partitions for each axis (currently only one axis can be partitioned). |
| 321 | custom_getter: Callable that allows overwriting the internal get_variable |
| 322 | method and has to have the same signature. |
| 323 | use_resource: If `True` use a ResourceVariable instead of a Variable. |
| 324 | synchronization: Indicates when a distributed a variable will be aggregated. |
| 325 | Accepted values are constants defined in the class |
| 326 | `tf.VariableSynchronization`. By default the synchronization is set to |
| 327 | `AUTO` and the current `DistributionStrategy` chooses when to synchronize. |
| 328 | aggregation: Indicates how a distributed variable will be aggregated. |
| 329 | Accepted values are constants defined in the class |
| 330 | `tf.VariableAggregation`. |
| 331 | |
| 332 | Returns: |
| 333 | The created or existing variable. |
| 334 | """ |
| 335 | collections = list(collections or []) |
| 336 | collections += [ops.GraphKeys.GLOBAL_VARIABLES, ops.GraphKeys.MODEL_VARIABLES] |
| 337 | var = variable( |
| 338 | name, |
| 339 | shape=shape, |
| 340 | dtype=dtype, |
| 341 | initializer=initializer, |
| 342 | regularizer=regularizer, |
nothing calls this directly
no test coverage detected