Variable store that carries a number of named Variables. New variable names and new variables can be created; all stored variables are initialized with the initializer passed to __init__. Attributes: vars: a dictionary with string names (same as passed in GetVar) as keys and the co
| 271 | |
| 272 | |
| 273 | class _VariableStore(object): |
| 274 | """Variable store that carries a number of named Variables. |
| 275 | |
| 276 | New variable names and new variables can be created; all stored |
| 277 | variables are initialized with the initializer passed to __init__. |
| 278 | |
| 279 | Attributes: |
| 280 | vars: a dictionary with string names (same as passed in GetVar) as keys and |
| 281 | the corresponding TensorFlow Variables as values. |
| 282 | """ |
| 283 | |
| 284 | def __init__(self): |
| 285 | """Create a variable store.""" |
| 286 | self._vars = {} # A dictionary of the stored TensorFlow variables. |
| 287 | self._partitioned_vars = {} # A dict of the stored PartitionedVariables. |
| 288 | self._store_eager_variables = False |
| 289 | |
| 290 | def get_hashtable(self, |
| 291 | name, |
| 292 | shape=None, |
| 293 | dtype=dtypes.float32, |
| 294 | initializer=None, |
| 295 | collections=None, |
| 296 | reuse=None, |
| 297 | trainable=None, |
| 298 | synchronization=VariableSynchronization.AUTO, |
| 299 | partitioner=None, |
| 300 | children=None): |
| 301 | if context.executing_eagerly(): |
| 302 | if not self._store_eager_variables and reuse: |
| 303 | raise RuntimeError( |
| 304 | "When eager execution is enabled variable reuse is only supported" |
| 305 | " when an EagerVariableStore is active. See the documentation on" |
| 306 | " EagerVariableStore for example usage.") |
| 307 | if self._store_eager_variables: |
| 308 | reuse = AUTO_REUSE |
| 309 | try: |
| 310 | dtype = dtype.base_dtype |
| 311 | except AttributeError: |
| 312 | # .base_dtype not existing means that we will try and use the raw dtype |
| 313 | # which was passed in - this might be a NumPy type which is valid. |
| 314 | pass |
| 315 | def _hashtable_getter(name, |
| 316 | shape=None, |
| 317 | dtype=dtypes.float32, |
| 318 | initializer=None, |
| 319 | collections=None, |
| 320 | reuse=None, |
| 321 | trainable=None, |
| 322 | partitioner=None, |
| 323 | children=None): |
| 324 | # HashTable cases |
| 325 | if partitioner is not None: |
| 326 | if not callable(partitioner): |
| 327 | raise ValueError( |
| 328 | "Partitioner must be callable, but received: %s" % partitioner) |
| 329 | return self._get_distribute_hashtable(name=name, |
| 330 | shape=shape, |
no outgoing calls
no test coverage detected