Creates a new variable with value `initial_value`. The new variable is added to the graph collections listed in `collections`, which defaults to `[GraphKeys.GLOBAL_VARIABLES]`. If `trainable` is `True` the variable is also added to the graph collection `GraphKeys.TRAINABLE_VARIABLE
(
self, # pylint: disable=super-init-not-called
initial_value=None,
trainable=None,
collections=None,
validate_shape=True,
caching_device=None,
name=None,
variable_def=None,
dtype=None,
expected_shape=None,
import_scope=None,
constraint=None,
synchronization=None,
aggregation=None,
shape=None)
| 1784 | """Ref-based implementation of variables.""" |
| 1785 | |
| 1786 | def __init__( |
| 1787 | self, # pylint: disable=super-init-not-called |
| 1788 | initial_value=None, |
| 1789 | trainable=None, |
| 1790 | collections=None, |
| 1791 | validate_shape=True, |
| 1792 | caching_device=None, |
| 1793 | name=None, |
| 1794 | variable_def=None, |
| 1795 | dtype=None, |
| 1796 | expected_shape=None, |
| 1797 | import_scope=None, |
| 1798 | constraint=None, |
| 1799 | synchronization=None, |
| 1800 | aggregation=None, |
| 1801 | shape=None): |
| 1802 | """Creates a new variable with value `initial_value`. |
| 1803 | |
| 1804 | The new variable is added to the graph collections listed in `collections`, |
| 1805 | which defaults to `[GraphKeys.GLOBAL_VARIABLES]`. |
| 1806 | |
| 1807 | If `trainable` is `True` the variable is also added to the graph collection |
| 1808 | `GraphKeys.TRAINABLE_VARIABLES`. |
| 1809 | |
| 1810 | This constructor creates both a `variable` Op and an `assign` Op to set the |
| 1811 | variable to its initial value. |
| 1812 | |
| 1813 | Args: |
| 1814 | initial_value: A `Tensor`, or Python object convertible to a `Tensor`, |
| 1815 | which is the initial value for the Variable. The initial value must have |
| 1816 | a shape specified unless `validate_shape` is set to False. Can also be a |
| 1817 | callable with no argument that returns the initial value when called. In |
| 1818 | that case, `dtype` must be specified. (Note that initializer functions |
| 1819 | from init_ops.py must first be bound to a shape before being used here.) |
| 1820 | trainable: If `True`, also adds the variable to the graph collection |
| 1821 | `GraphKeys.TRAINABLE_VARIABLES`. This collection is used as the default |
| 1822 | list of variables to use by the `Optimizer` classes. Defaults to `True`, |
| 1823 | unless `synchronization` is set to `ON_READ`, in which case it defaults |
| 1824 | to `False`. |
| 1825 | collections: List of graph collections keys. The new variable is added to |
| 1826 | these collections. Defaults to `[GraphKeys.GLOBAL_VARIABLES]`. |
| 1827 | validate_shape: If `False`, allows the variable to be initialized with a |
| 1828 | value of unknown shape. If `True`, the default, the shape of |
| 1829 | `initial_value` must be known. |
| 1830 | caching_device: Optional device string describing where the Variable |
| 1831 | should be cached for reading. Defaults to the Variable's device. If not |
| 1832 | `None`, caches on another device. Typical use is to cache on the device |
| 1833 | where the Ops using the Variable reside, to deduplicate copying through |
| 1834 | `Switch` and other conditional statements. |
| 1835 | name: Optional name for the variable. Defaults to `'Variable'` and gets |
| 1836 | uniquified automatically. |
| 1837 | variable_def: `VariableDef` protocol buffer. If not `None`, recreates the |
| 1838 | Variable object with its contents, referencing the variable's nodes in |
| 1839 | the graph, which must already exist. The graph is not changed. |
| 1840 | `variable_def` and the other arguments are mutually exclusive. |
| 1841 | dtype: If set, initial_value will be converted to the given type. If |
| 1842 | `None`, either the datatype will be kept (if `initial_value` is a |
| 1843 | Tensor), or `convert_to_tensor` will decide. |
nothing calls this directly
no test coverage detected