Gets an existing variable with this name or create a new one.
(self,
var_store,
name,
shape=None,
dtype=None,
initializer=None,
collections=None,
reuse=None,
trainable=True,
synchronization=VariableSynchronization.AUTO,
partitioner=None,
children=None)
| 1525 | aggregation=aggregation) |
| 1526 | |
| 1527 | def get_hash_table(self, |
| 1528 | var_store, |
| 1529 | name, |
| 1530 | shape=None, |
| 1531 | dtype=None, |
| 1532 | initializer=None, |
| 1533 | collections=None, |
| 1534 | reuse=None, |
| 1535 | trainable=True, |
| 1536 | synchronization=VariableSynchronization.AUTO, |
| 1537 | partitioner=None, |
| 1538 | children=None): |
| 1539 | """Gets an existing variable with this name or create a new one.""" |
| 1540 | if partitioner is None: |
| 1541 | partitioner = self._partitioner |
| 1542 | if not context.executing_eagerly(): |
| 1543 | if reuse is None: |
| 1544 | reuse = self._reuse |
| 1545 | else: |
| 1546 | reuse = AUTO_REUSE |
| 1547 | |
| 1548 | full_name = self.name + "/" + name if self.name else name |
| 1549 | # Variable names only depend on variable_scope (full_name here), |
| 1550 | # not name_scope, so we reset it below for the time of variable creation. |
| 1551 | with ops.name_scope(None): |
| 1552 | # Check that `initializer` dtype and `dtype` are consistent before |
| 1553 | # replacing them with defaults. |
| 1554 | if (dtype is not None and initializer is not None and |
| 1555 | not callable(initializer)): |
| 1556 | init_dtype = ops.convert_to_tensor(initializer).dtype.base_dtype |
| 1557 | if init_dtype != dtype: |
| 1558 | raise ValueError("Initializer type '%s' and explicit dtype '%s' " |
| 1559 | "don't match." % (init_dtype, dtype)) |
| 1560 | if initializer is None: |
| 1561 | initializer = self._initializer |
| 1562 | if dtype is None: |
| 1563 | dtype = self._dtype |
| 1564 | return var_store.get_hashtable(full_name, |
| 1565 | shape=shape, |
| 1566 | dtype=dtype, |
| 1567 | initializer=initializer, |
| 1568 | reuse=reuse, |
| 1569 | collections=collections, |
| 1570 | trainable=trainable, |
| 1571 | synchronization=synchronization, |
| 1572 | partitioner=partitioner, |
| 1573 | children=children) |
| 1574 | |
| 1575 | def get_embedding_variable(self, |
| 1576 | var_store, |